第一种:通过CSS是div实现全屏效果
直接上代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
height: 100%;
}
#container,.sections,.section{
height: 100%;
}
.section{
background-image: url(../../static/img/indexBg.png);
color: #fff;
text-align: center;
background-size: cover;
background-position: 50% 50%;
}
</style>
<body>
<div id="container">
<div class="sections">
<div class="section">
猫咪,你好啊。。。。
</div>
</div>
</div>
</body>
</html>
全屏要素:
1.全屏的元素及其父元素都要设置height:100%。
2,将html,body标签设置height:100%。
注:height:100%是跟随其父元素高度变化而变化的。
直接上代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<style>
*{
margin: 0;
padding: 0;
}
#container{
background: url(../../static/img/indexBg.png) no-repeat top center;
background-size: cover;
background-attachment: fixed;
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
</style>
<body>
<div id="container">
<div class="sections">
<div class="section" id="section0">
猫咪,你好啊。。。。
</div>
</div>
</div>
</body>
</html>