<h1>CSS layout: 100%height with header and footer</h1>
<p>Sometimes things that used to be really simple with tables can still appear pretty hard with CSS. This layout for instance would consist of 3 cells; two with a fixed height, and a third one in the center filling up the remaining space. Using CSS, however, you have to take a different approach.</p>
</div>
<divid="content">
<h2>Min-height</h2>
<p>
The #container element of this page has a min-height of 100%. That way, if the content requires more height than the viewport provides, the height of #content forces #container to become longer as well. Possible columns in #content can then be visualised with abackground image on #container; divs are not table cells, and you don't need (or want) the fysical elements to create such a visual effect. If you're not yet convinced; think wobbly lines and gradients instead of straight lines and simple color schemes.
</p>
<h2>Relative positioning</h2>
<p>
Because #container has a relative position, #footer will always remain at its bottom; since the min-height mentioned above does not prevent #container from scaling, this will work even if (or rather especially when) #content forces #container to become longer.
</p>
<h2>Padding-bottom</h2>
<p>
Since it is no longer in the normal flow, padding-bottom of #content now provides the space for the absolute #footer. This padding is included in the scrolled height by default, so that the footer will never overlap the above content.
</p>
<p>
Scale the textsizea bit or resize your browser window to test this layout. The <ahref="css/layout1.css">CSS file is over here</a>.
</p>
<p>
<ahref="../css.html">Back to CSS Examples</a>
</p>
</div>
<divid="footer">
<p>
This footer is absolutely positioned to bottom:0; of #container. The padding-bottom of #content keeps me from overlapping it when the page is longer than the viewport.
</p>
</div>
</div>
<scriptsrc=""type="text/javascript"></script>
<scripttype="text/javascript">
_uacct ="UA-472607-1"; urchinTracker();
</script>
</body>
/**
* 100% height layout with header and footer
* ----------------------------------------------
* Feel free to copy/use/change/improve
*/
html,body{
margin:0;
padding:0;
height:100%;/* needed for container min-height */
background:gray;
font-family:arial,sans-serif;
font-size:small;
color:#666;
}
h1{
font:1.5em georgia,serif;
margin:0.5em 0;
}
h2{
font:1.25em georgia,serif;
margin:0 0 0.5em;
}
h1,h2,a{
color:orange;
}
p{
line-height:1.5;
margin:0 0 1em;
}
div#container {
position:relative;/* needed for footer positioning*/
<p>We don't always get to design our own form layouts. The form below, for instance, looks more suited for print than for the web, but that's just the way things sometimes go.</p>
</div>
<divid="content">
<h2>Widht:100%</h2>
<p>
Instead of setting the widthfor each individual form element, why not simply let them scale to a grid automatically? The form below does exactly that.A fixed table layout creates a solid grid to work with. This grid is then used with varying colspan values, and the 100%widthforinput fields does the rest.
Granted, using tables for forms may be questionable, but you're entering a world of pain if you don't do it for complex form layouts. The <ahref="css/sample1.css">CSS file is over here</a>.
</p>
<p>
<ahref="../css.html">Back to CSS Examples</a>
</p>
</div>
</div>
<scriptsrc=""type="text/javascript"></script>
<scripttype="text/javascript">
_uacct ="UA-472607-1"; urchinTracker();
</script>
</body>
</html>
/**
* 100% height layout with header and footer
* ----------------------------------------------
* Feel free to copy/use/change/improve
*/
table{
table-layout:fixed;/* force a solid grid */
border-collapse:collapse;
margin: 0 auto 1em;
width:450px;
}
tableth,tabletd{
white-space:nowrap;/* don't want wrapping text */
padding:2px 20px 2px 5px;/* right padding for required field marker */