我正在尝试创建一个包含两个部分的容器 - 顶部将是一个滚动 div,它占据其容器垂直高度的 100%,减去粘性页脚的高度。粘性页脚不能有硬编码的高度(因为它可以在两种不同高度的两种模式下工作),这是我感到困扰的地方。我宁愿不使用 js,如果可能的话只使用 css。
HTML
<div class="container">
<div class="scrollArea">
a<br/>b<br/>c<br/>d<br/>
a<br/>b<br/>c<br/>d<br/>
a<br/>b<br/>c<br/>d<br/>
a<br/>b<br/>c<br/>d<br/>
</div>
<div class="footer">
<!-- the contents of the footer will determine the height needed -->
</div>
</div>
CSS
.container {
position: relative;
height: 100%;
width: 100%;
}
.scrollArea {
position: absolute;
top: 0px;
bottom [height of sticky footer]; left: 0px;
right: 0px;
overflow-x: hidden;
overflow-y: scroll;
}
.footer {
position: absolute;
bottom: 0px;
height: [height of sticky footer];
left: 0px;
right: 0px;
}