【发布时间】:2016-04-06 20:57:02
【问题描述】:
我拥有的是container 后跟两个子元素content 和footer 的简单结构。
footer 有一个固定的高度,content 应该填充剩余的空白空间。使用display:table; 很容易实现这一点,但由于某种原因,如果content 元素的内容超过网站窗口高度,我无法弄清楚如何让其溢出工作?
这是一个JSFiddle,如果您将content_child 高度设置为10px,您可以看到content 元素很好地填充了空间,但是当content_child 大很多时content 元素不应该扩展它现在的方式,我在这里缺少什么?
如果可能的话,我宁愿不使用 JavaScript 来解决这个问题。
body, html{
height: 100%;
padding: 0px;
margin: 0px;
}
.container{
display:table;
background; black;
width: 100%;
background: black;
height: 100%;
}
.top{
background: blue;
display:table-row;
height: 100%;
}
.bottom{
background: red;
height: 60px;
}
.content{
height: 100%;
overflow: hidden;
padding: 5px;
}
.content_child{
height: 1000px;
background: grey;
}
<div class="container">
<div class="top">
<div class="content">
<div class="content_child"></div>
</div>
</div>
</div>
<div class="bottom">
</div>
</div>
【问题讨论】:
-
顺便说一句;你有一个额外的关闭 div。看起来您正在尝试关闭
<div class="content_child">两次 -
你想要一个固定的页脚还是你想要实现什么?无论如何,很可能有比使用表格更好的方法来实现您想要做的事情。因此,让我们不要从解决方案开始,而是从问题开始。
-
@Roope 是的,页脚应该固定,内容填充其余空间
-
在溢出的情况下内容是否可以滚动,或者如何?
-
@roope 内容应始终填充网站上的剩余空间,如果其内容大于网站,则应具有溢出-y:滚动