<body>
<!-- 背景层 -->
<div class="bg"></div>
</body>
html, body {
width: 100%;
height: 100%;
}
body {
overflow: hidden;
position: relative;
}
.bg {
position: absolute;
left: 0;
top: 0;
z-index: 0;
width: 100%;
height: 100%;
background: url('page_1.jpg') no-repeat center center fixed;
}
1.背景图片设置全屏CSS方法(推荐使用)
html{
background: url('images/page1.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
2.背景图片设置全屏 图片层方法
注意:此方法图片会拉伸失真
<body>
<img src="images/page1.jpg" width='100%' height='100%' class="bgimg">
</body>
.bgimg{
position: fixed;
left:0px;
top:0px;
margin:auto;
width:100%;
height:100%;
z-index:-1;
}
3.给背景图片设置一层透明的蒙住的版
<body>
<div class="cover"></div>
</body>
.cover{
position: fixed;
left:0px;
top:0px;
z-index: -1;
opacity: 0.6;
height: 100%;
width: 100%;
background: black;
}
本文介绍了三种不同的方法来实现网页中背景图片的全屏显示效果。第一种方法通过CSS属性实现背景图片自适应;第二种方法利用图片层,但可能会导致图片变形;第三种方法是在背景图片上叠加一层透明层,增强视觉效果。
1110

被折叠的 条评论
为什么被折叠?



