html代碼:
<body>
<div class="content"></div>
<div class="footer"></div>
</body>
body {
display: flex;
flex-flow: column;
min-height: 100vh;
}
.content {
flex: 1;
}
.footer{
flex: 0;
}
這種方法就是利用flex佈局對視窗高度進行分割。footer的flex設爲0,這樣footer獲得其固有的高度;content的flex設爲1,這樣它會充滿除去footer的其他部分。