Filled Context With CSS Flex
by Bilal AFSAR
HTML
<div class="box">
<header class="row">
<p><b>header</b>
<br />
<br />(sized to content)</p>
</header>
<section class="row">
<p>
<b>content</b>
(fills remaining space)
</p>
</section>
<footer class="row">
<p><b>footer</b> (fixed height)</p>
</footer>
</div>
CSS
html,
body {
height: 100%;
margin: 0;
background-color:yellow;
}
.box {
display: flex;
flex-flow: column;
height: 100%;
background-color:red;
}
.box .row {
border: 1px dotted grey;
}
.box header.row {
flex: 0 1 auto;
/* The above is shorthand for:
flex-grow: 0,
flex-shrink: 1,
flex-basis: auto
*/
}
.box section.row {
flex: 1 1 auto;
border:5px solid green;
}
.box footer.row {
flex: 0 1 40px;
}