【发布时间】:2018-11-20 18:35:48
【问题描述】:
我们有一个带有overflow-y:scroll 的容器,它的页脚必须是粘性的(底部为 0),除非滚动容器内的内容 + 页脚的高度(动态)大于容器高度。
HTML:
<div class="wrapper">
<div class="scroll">
<div class="content">
Lorem ipsum dolor sit amet
</div>
<div class="footer">
This must stick to the bottom until .content is too long, then go below it
</div>
</div>
</div>
.content 和 .footer 可以有更多或更少的内容。
如果可能,我们不想为此使用 JS。
我在这里创建了一个有几个状态的小提琴:http://jsfiddle.net/bqvtf1zo/1/
删除 .footer 上的 position: absolute 可以解决“少量内容”的情况(参见小提琴),但会破坏其他 2 种情况。
【问题讨论】:
标签: html css sticky sticky-footer