<body>
<div>
<!--背景图片-->
<div id="web_bg" style="background-image: url(./img/bg.jpg);"></div>
<!--其他代码 ... -->
</div>
</body>
以上是需求代码
以下是实现css样式代码
#web_bg{
position:fixed;
top:;
left:;
width:100%;
height:100%;
min-width: 1000px;
z-index:-10;
zoom:;
background-color: #fff;
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-o-background-size: cover;
background-position: center 0;
}
通过以上操作,我们可以实现将一张图片作为网页背景,且不会因为浏览器的尺寸导致留白和重复