【发布时间】:2014-12-05 15:55:29
【问题描述】:
here我放了一些标准布局的简单示例(页眉、带有可滚动 div 的内容、页脚)
我坚持使用 css 拼图 - 如何拉伸滚动 div div#content > div#scroll 使其将页面填充到页脚?
div#page { /* aka html */
height : 100%;
width : 100%;
margin : 0 auto;
box-sizing : border-box;
overflow : auto;
}
div.cleaner {
clear : both;
}
header {
display : block;
width : 100%;
}
header > div#left_head {
float : left;
width : 50%;
box-sizing : border-box;
border : dotted blue 1px;
}
header > div#right_head {
float : right;
width : 50%;
box-sizing : border-box;
text-align : right;
border : dotted blue 1px;
}
footer {
display : block;
width : 100%;
position : absolute;
left : 0px;
bottom : 0px;
}
footer > div#left_foot {
float : left;
width : 50%;
box-sizing : border-box;
border : dotted green 1px;
}
footer > div#right_foot {
float : right;
width : 50%;
box-sizing : border-box;
text-align : right;
border : dotted green 1px;
}
/*---------------->8---------------*/
div#content {
width : 90%;
margin : 0 auto;
border : dotted black 1px;
}
div#content > div#scroll {
height : 200px;
overflow-y: auto;
}
<div id="page">
<header>
<div id="left_head">
<span>here is left header</span>
</div>
<div id="right_head">
<span>here is right header</span>
</div>
</header>
<div id="dummy" class="cleaner" />
<div id="content">
<div id="scroll">
<p>scrollable content</p>
<p>scrollable content</p>
<p>scrollable content</p>
<p>scrollable content</p>
<p>scrollable content</p>
<p>scrollable content</p>
<p>scrollable content</p>
<p>scrollable content</p>
<p>scrollable content</p>
<p>scrollable content</p>
<p>scrollable content</p>
<p>scrollable content</p>
<p>scrollable content</p>
<p>scrollable content</p>
<p>scrollable content</p>
</div>
</div>
<footer>
<div id="left_foot">
<span>here is left foot</span>
</div>
<div id="right_foot">
<span>here is right foot</span>
</div>
</footer>
</div>
在给定的示例中,我通过 200px 的硬编码值限制了高度。
任何想法,cmets - 赞赏。
谢谢!
【问题讨论】:
-
不确定您的小提琴链接 (404) - 但找到了 this one?
-
正确.. 很抱歉造成混乱。我编辑了链接。
-
@jbutler483 我不明白。
overflow-x控制浏览器的操作,以防内容超出水平边界(左右滚动)。但我需要垂直拉伸 div。我可以玩position : absolute并设置top, left, bottom, right。但我觉得它太“僵化”了——页眉/页脚的大小可以改变。此外,将 div#content 放在中间也会有问题。 -
您可能真的对使用粘性页脚感兴趣(尽管我个人不是他们的粉丝)?
-
@AlexLaban 对不起,我想我在你编辑之前误解了这个问题。请忽略我原来的评论。 =