Similar to the idea already posted there is this way:
body{
margin: 0;
padding: 0;
height: 100%;
padding: 50px 0;
}
header, footer{
height: 50px;
width: 100%;
background: #333;
position: fixed;
}
header{ top: 0;}
footer{ bottom: 0;}
#content{
background: gold;
position: absolute;
width: 100%;
bottom: 50px;
top: 50px;
}
<header></header>
<div id="content"></div>
<footer></footer>
You assign header
and footer
a desired height
, these heights will be used later to specify the div#content
spacing so that it occupies the remaining space.
This is done by assigning both a position: fixed
, and bottom
and top
.
With div#content
having a position: absolute
you do not need to specify height
, but top
and bottom
, which are the height of header
and footer
, respectively. So the% with% of this height
will be automatic. If you want content with a scroll bar, just give div
.