html - 使以下 div 扩展到底部然后滚动

标签 html css

我有以下设计

enter image description here

如何让橙色的div从头到底展开,内容再大再滚动,同时让footer保持在页面底部?

我尝试将 div 定位为 position:absolute 并带有 bottom:footers's heightoverflow-y:scroll,但如果我这样做它与头部重叠。

最佳答案

您可以将headerfooter 元素分别设置为position: fixed 到顶部和底部。从那里您只需将 padding-toppadding-bottom 添加到中央内容 div,这样其中的内容就不会重叠。试试这个:

<header></header>
<div id="content"></div>
<footer></footer>
header {
    height: 150px;
    position: fixed;
    top: 0;
    width: 100%;
}

#content {
    padding: 150px 0 100px;
}

footer {
    height: 100px;
    position: fixed;
    bottom: 0;
    width: 100%;
}

Example fiddle

关于html - 使以下 div 扩展到底部然后滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31286621/

相关文章:

html - Plotly-Dash 中元素的定位

css - Materialise CSS 通知计数不显示计数数字

html - 如何通过字符引用将 @font-face 与 Noto Emoji 字体一起使用?

html - 轻松对齐旋转按钮

html - 如何为标题标题添加部分边框?

html - 3 列 div 布局不适合我

html - 图像沿文本

javascript - Bootstrap 选项卡在 Vue 应用程序中不起作用

html - 很难在滚动条上创建固定标题。典型的解决方案不再适合我

html - div 子元素未出现在 div 中