【发布时间】:2020-12-06 17:59:34
【问题描述】:
我很难调整网站的布局,希望有人能提供帮助。问题是高度为 100% 的主体占用了浏览器的高度,但它不会超出子元素的范围。因此,例如在以下布局中,页脚位于 .second div 上方。目标是让 .first 占据浏览器的全部高度并保持原样。
100vh - 由于移动问题,不是一个选项,因此如果 100% 可行,请告诉我
谢谢!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
html, body{
min-height: 100%;
height: 100%;
background-color:blue;
margin: 0;
padding: 0;
}
.wrapper{
height: 100%;
background-color: yellow;
}
.main{
height:100%;
background-color: red;
}
.first{
height: 100%;
background-color: green;
}
.second{
background-color:brown;
}
.footer{
background: black;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="main">
<div class="first">
First Page
</div>
<div class="second">
Second Page
</div>
</div>
<div class="footer">
Footer
</div>
</div>
</body>
</html>
【问题讨论】:
-
.first是否也需要为 100% 还是仅用于演示? -
.first 需要为 100%。其他人没有。