在项目中遇到网页全屏背景的问题?
我是这样解决的,不知有什么更好的方法?
<body>
<header></header>
<main></main>
<footer></footer>
<div class="body_bg">
<img src="bg1.png" width="100%" height:"100%"></img>
</div>
<body>
.body_bg{
position:absolute;
left:0;
right:0;
bottom:0;
top:0;
z-index:-1
}
html {
height: 100%;
}
body {
min-height: 100%;
background-image: url();
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
}
背景图足够大即可~
楼主这个方法目测是目前最好的,我也一直用的这种。
或者说通过JS算。。。
http://.com/q/1010000003769052/a-1020000003769745
如果把absolute
定位换成fixed
定位的话,那或许更赞……
或者呢,直接把background
写到html
标签里,更直接……
.body-big{width:100vw;height:100vh;min-width:1024px;min-height:600px;}
Img{width:100%;height:100%;}