我所拥有的是一个简单的结构,由一个名为
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>
display:table
,请改用display:flex
。这样应该比较简单,底部的stretch为0,内容区域的stretch为1。 - Aleks G