Update
An easy way to do this for modern browsers (2015) with display:flex :
html, body {height:100%; padding:0; margin:0; width:100%;} body {display:flex; flex-direction:column;} #main {flex-grow:1;} header {min-height:50px; background:green;} #main {background:red;} footer {min-height:50px; background:blue;}
<header>header</header> <div id="main" role="main">content</div> <footer>footer</footer>
The above allows both a fixed height for the header and footer (just add height to the styles) and a variable height (as shown currently - may vary depending on the contents of the header and footer), while the content takes up the rest of the space.
If the content is larger than the document, the footer will be moved down.
Old post:
There are several ways to do this using pure css. Basically you need to start with the html structure as follows:
<div id="wrapper"> <div class="top"></div> <div class="middle"> <div class="container"> </div> </div> <div class="bottom"></div> </div>
Version 1 uses border-box, so it will not be compatible with older browsers (and you may need to add moz, webkit and ms prefixes to make them work in all browsers):
html, body { height: 100%; margin: 0; padding: 0; } #wrapper { padding: 100px 0 75px 0; height: 100%; box-sizing: border-box; } .middle { min-height: 100%; position: relative; } .top { margin-top: -100px; height: 100px; } .bottom { margin-bottom: -75px; height: 75px; } .container { padding: 10px; }
Version 1
Version 1 with content
Vertical column version 1
Version 2 uses absolute positioning and is a bit more browser friendly:
html, body {min-height:100%; padding:0; margin:0;} #wrapper {padding:50px 0; position:absolute; top:0; bottom:0; left:0; right:0;} .middle {min-height:100%;} .top {margin-top:-50px; height:50px;} .bottom {margin-bottom:-50px; height:50px;} .container {padding:10px;}
Version 2
Version 2 with content
Vertical column version 2
Version 3 changes html slightly, but is more reliable if you have variable headers and footers:
<div id="wrapper"> <div class="table"> <div class="top row"><div class="cell"></div></div> <div class="middle row"><div class="container cell"></div></div> <div class="bottom row"><div class="cell"></div></div> </div> </div>
Css
html, body {min-height:100%; padding:0; margin:0;} #wrapper {position:absolute; top:0; bottom:0; left:0; right:0;} .table {display:table; width:100%; height:100%;} .row {display:table-row;} .cell {display:table-cell;} .middle {height:100%;} .container {padding:10px;}
Version 3
Version 3 with different headers and footers
Version 3 with content
Center column version 3