关于全屏背景更好的解决方法?

在项目中遇到网页全屏背景的问题?
我是这样解决的,不知有什么更好的方法?

<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
}
阅读 3.7k
5 个回答
html {
    height: 100%;
}
body {
    min-height: 100%;
    background-image: url();
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;
}

背景图足够大即可~

如果把absolute定位换成fixed定位的话,那或许更赞……

或者呢,直接把background写到html标签里,更直接……

楼主这个方法目测是目前最好的,我也一直用的这种。
或者说通过JS算。。。

.body-big{width:100vw;height:100vh;min-width:1024px;min-height:600px;}
Img{width:100%;height:100%;}

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题