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 attribute to header
and to the footer
one height
desired, these heights will be used further forward to specify the spacing of the div#content
for it to occupy the remaining space.
Once this is done, just assign to both a position: fixed
, and bottom
and top
.
With the div#content
having a position: absolute
you do not need to specify the height
and yes the top
and bottom
, being the height of header
and of footer
, respectively. Thus the height
of this div
will be automatic. If you want a scrollbar content, just give a overflow: auto
.
Place a max-height in the central div, so that it occupies as much space as possible between the two Divs.
– Tiago P.C