为什么背景大小:100%100%;不能使用这个SVG?

时间:2017-10-27 16:03:05

标签: html css svg background-image stretch

看一下例子:



.container {
   background-image:url("http://svgshare.com/i/3cM.svg");
   background-position:center center;
   background-repeat:no-repeat;
   width:400px;
   height:200px;
   background-color:#eef;
   border-bottom:1px solid #000;
   background-size:100% 100%;
}

<div id="container1" class="container"></div>
&#13;
&#13;
&#13;

相关问题:Stretch a background image (SVG) to 100% width and 100% height?

2 个答案:

答案 0 :(得分:3)

打开.svg文件并设置

  

preserveAspectRatio="none"

在SVG标签内。

答案 1 :(得分:0)

正如评论中所建议的那样,将svg容器包装在另一个容器中,并为包装器提供所需的尺寸。在这种情况下,我将包装器设置为100vw宽度和100vh高度。更改包装器尺寸并注意svg将遵循。

html, body {
  padding:0;
  margin:0;
}

.wrapper {
  width:100vw;
  height:100vh;
}

.container {
   background-image:url("http://svgshare.com/i/3cM.svg");
   background-position:center center;
   background-repeat:no-repeat;
   width:100%;
   height:100%;
   background-color:#eef;
   border-bottom:1px solid #000;
   background-size:100% 100%;
}
<div class="wrapper">
  <div id="container1" class="container"></div>
</div>

相关问题