Generally speaking, absolute positioning should be avoided unless you really do want the element removed from the document's flow. If you have a page where #main
ends up having shorter content than #sidebar
and the user's display isn't tall enough to display all of #sidebar
's contents, you're going to have your content clipped off.
My favored way of achieving equal height columns is to use the display: table
CSS properties.
html,body {
margin:0;
padding:0;
width:100%;
height:100%;
}
body { display: table }
#sidebar {
width:25%;
border-right:1px solid #222;
background-color: #E0E0E0;
}
#sidebar, #main {
display:table-cell;
vertical-align: top; /* optional */
}
h1 {
padding:2%;
margin-top: 0;
/* margin:0; */
/* defining the margin as zero aligns
* everything at the top */
}
There's other ways, of course, but this one is less brittle than floats or absolute positioning. The only down side is that IE7 doesn't support these properties, so they'll continue using the element's previously defined (or default) display setting (for div
, it will be block
).