I've been trying to set three columns to 100% height of a main content area with a header and footer on the top and bottom.
The desired behavior is:
- When the content does not take up the screen, the footer is at the bottom of the screen, and the middle area stretches to fill the middle space.
- When the content takes up more than the screen, the footer is at the bottom of the content, not the screen.
I ended up going with the table
and table-cell
solution, but the middle section extends below the footer - which causes an unnecessary scrollbar to appear, see:
https://jsfiddle.net/rwone/rqmrxfbp
A similar question was asked here.
Relevant HTML
<div id="container">
<div id="left_col"></div>
<div id="main_content"></div>
<div id="right_col"></div>
</div>
<div id="footer"></div>
CSS
#container {
display: table;
width: 100%;
height: 100%;
}
#left_col {
background: orange;
display: table-cell;
width: 15%;
}
#main_content {
background: #ff0;
display: table-cell;
}
#right_col {
background: green;
display: table-cell;
width: 15%;
}
#footer {
background: #3a3a3a;
height: 200px;
position: absolute;
width: 100%;
bottom: 0;
}
Continued on your choice to using
display: table
, where I added the proper markup instead of using anonymous table elements.In the future one don't know how those might render so I think have them added will make sure they work as intended (and make it easier to read the markup).
With
flexbox
the markup can be cleaned up a littleHope this works.