我想这就是你要找的。如果要使用flex,可以将其方向设置为
column
并设置
height
容器的
100vh
,然后设置
flex-grow
属性设置为页的正文,以便使用剩余空间。
最好全屏查看
.container {
display: flex;
flex-direction: column;
height: 100vh;
}
header {
background: red;
height: 40px;
}
.body {
flex-grow: 1;
background: green;
}
footer {
background: blue;
height: 40px;
}
<div class="container">
<header>
</header>
<div class="body">
</div>
<footer>
</footer>
</div>