我想使用flexbox的全高应用程序.我在这个链接中找到了我想要的使用旧flexbox布局模块(display: box;
和其他东西)的内容:CSS3 Flexbox full-height app and overflow
对于只支持旧版本flexbox CSS属性的浏览器来说,这是一个正确的解决方案.
如果我想try 使用较新的flexbox属性,我将try 在同一链接中使用第二个解决方案,作为一个黑客:使用一个包含height: 0px;
的容器.它使得显示一个垂直滚动.
我不太喜欢它,因为它会带来其他问题,与其说是解决方案,不如说是一种变通方法.
html, body {
height: 100%;
}
#container {
display: flex;
flex-direction: column;
height: 100%;
}
#container article {
flex: 1 1 auto;
overflow-y: scroll;
}
#container header {
background-color: gray;
}
#container footer {
background-color: gray;
}
<section id="container" >
<header id="header" >This is a header</header>
<article id="content" >
This is the content that
<br />
With a lot of lines.
<br />
With a lot of lines.
<br />
This is the content that
<br />
With a lot of lines.
<br />
<br />
This is the content that
<br />
With a lot of lines.
<br />
<br />
This is the content that
<br />
With a lot of lines.
<br />
</article>
<footer id="footer" >This is a footer</footer>
</section>
我还准备了一个带有基本示例的JSFdle:http://jsfiddle.net/ch7n6/
这是一个全高的HTML网站,由于内容元素的flexbox属性,页脚位于底部.我建议你在CSS代码和结果之间移动条来模拟不同的高度.