http://jsfiddle.net/unh5rw9t/1/
HTML
<body>
<div id="wrapper">
<div id="menu">
1
</div>
<div id="content">2
<div id="half_of_content">2.1</div>
</div>
<div id="footer" style="">
3
</div>
</div>
</body>
CSS
html,body {
height: 100%;
margin: 0;
}
#wrapper {
display: flex;
flex-flow: column;
height: 100%;
}
#menu {
height: 70px;
background-color: purple
}
#content {
flex: 1;
height: 100%;
background-color: green;
}
#half_of_content {
height: 50%;
background-color: yellow;
}
#footer {
height: 100px;
background-color: cyan
}
#half_of_content
具有height: auto
,因此您无法在其子元素的height
中使用百分比。但是您可以再次使用相同的技巧,例如,如果您想要一个子元素为70%
,请设置flex:70
并添加带有flex:100
的伪元素。 - Oriolheight
,尽管height
是主要实现。看起来 FF 正在放宽其解释。 - Michael Benjaminheight
值更有意义。前几天我发现了另一个有趣的情况,其中容器的高度并不直接取决于内容的高度,但通过min-height: auto
实现。我想我们必须等到新的规范澄清这些情况。 - Oriol