【发布时间】:2015-03-23 13:26:07
【问题描述】:
我正在尝试将图像 (.svg) 的宽度填充到我的 DIV 中,使其可以拉伸,但我的图像只有 100% 的宽度,并且随着高度它裁剪了底部。
我怎样才能让它拉伸高度到视口高度? 我已经尝试将图像变成背景图像,但这在设计中不起作用。
.flag {
position: absolute;
z-index: -1;
background-size: contain;
}
#flag img{
width: 100vh;
height: 100vh;
}
<section class="cover" style="min-height: 100vh">
<img src="img/background.svg" class="flag"></div>
</section>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1024px"
height="768px" viewBox="0 0 1024 768" enable-background="new 0 0 1024 768" xml:space="preserve">
<g id="Layer_1" display="none">
<rect x="-0.5" y="0.5" display="inline" fill="#FFFFFF" stroke="#000000" stroke-miterlimit="10" width="57" height="768"/>
<rect x="967.5" y="0.5" display="inline" fill="#FFFFFF" stroke="#000000" stroke-miterlimit="10" width="57" height="768"/>
<rect x="-0.5" y="0.5" display="inline" fill="none" stroke="#000000" stroke-miterlimit="10" width="1025" height="57"/>
<rect x="-0.5" y="711.5" display="inline" fill="none" stroke="#000000" stroke-miterlimit="10" width="1025" height="57"/>
</g>
<g id="Layer_2">
<rect fill="#FFFFFF" width="1024" height="768"/>
<rect y="103" width="1022" height="34"/>
<rect y="171" width="1022" height="34"/>
<rect y="239" width="1022" height="34"/>
<rect y="631" width="1022" height="34"/>
<rect y="563" width="1022" height="34"/>
<rect y="495" width="1022" height="34"/>
<rect x="55" y="58" fill="#E5452D" width="912" height="654"/>
<rect x="55" y="385" fill="#0698CF" width="912" height="327"/>
</g>
</svg>
【问题讨论】:
-
请同时发布
svg代码。
标签: html css svg viewport stretch