我正在尝试将背景图像拉伸到父div的100%宽度和高度.IE8当然不支持background-size.我尝试了以下代码,但它不起作用.
.box:before {
background: url(images/body_background2.png) no-repeat;
display: block;
position: absolute;
z-index: -1;
height: 100%;
width: 100%;
content: '';
}
Run Code Online (Sandbox Code Playgroud)
Zet*_*eta 12
使用<img>with position:fixed;top:0;left:0;width:100%;height:100%;和negative z-index.很遗憾没有办法在IE 8中仅使用CSS实现此行为.
有关详细信息,请参阅以下文章:如何在网页中拉伸背景图像.
如果您希望使用图像作为给定<div>尝试的背景,请尝试以下方法:
<div class="fullbackground">
<img class="fullbackground" src="yourImageSrc" />
</div>
Run Code Online (Sandbox Code Playgroud)
.fullbackground{
position:relative;
}
img.fullbackground{
position:absolute;
z-index:-1;
top:0;
left:0;
width:100%; /* alternative: right:0; */
height:100%; /* alternative: bottom:0; */
}
Run Code Online (Sandbox Code Playgroud)