html 使用svg矢量图时无法 调整宽高问题解决,不能像图片一样设置宽高比例问题

引入的路径后加  #svgView(preserveAspectRatio(none))

具体代码如下

 修改前
<img src="@/assets/svgs/full_screen_full.svg" class="im">
修改后
<img src="@/assets/svgs/full_screen_full.svg#svgView(preserveAspectRatio(none))" class="im">

.im{
    //transform: scale(2,1); 
    width: 100px;
    height: 200px;
}



同时对于svg作为背景的情况也适用




<template>
    <div class="parent-container">
      
        <el-row  v-for="rindex of 4" :key="rindex" :id="rindex" :ref="rindex">
            <point v-for="cindex of 8" :key="cindex" :widthp="widthp" :heightp="heightp"  :sizep="sizep"  :color1="color1"  :color2="getpcolr2(rindex,cindex)"></point>
        </el-row>
    </div>
    <img src="@/assets/svgs/full_screen_full.svg#svgView(preserveAspectRatio(none))" class="im">

    <div class="svg-container">
  <svg viewBox="0 0 100 100" width="100%">
    <!-- SVG内容 -->
  </svg>
</div>

</template>




.parent-container {
  padding: 1.5%;
  display: inline-block;
  background-image: url('@/assets/svgs/full_screen_full.svg#svgView(preserveAspectRatio(none))');
  background-repeat:no-repeat;
  position: contain;
  background-size: 110% 100%;
  background-color: rgb(129, 132, 134);
}

 

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值