I disagree with Dominic Rodger: a framework would be massive overkill for something that simple. Sure, you should have some kind of underlying grid, but you don't need the entirety of 960.gs, blueprint or any other "framework" that just pollutes your markup with unnecessary classes.
Frameworks require the use of predefined class names like .grid_2
, .grid_12
and the like, eternally binding you to exactly that layout. This kind of defeats the decoupling of HTML and CSS: a redesign would require you to alter both your stylesheet AND your markup, which gets out of hand pretty quickly. I generally just wouldn't recommend it.
Your requirements are pretty basic and can do without frameworks just fine. Basically, all you have to do is add another container to your markup (also, you should use id
instead of class
if only one of these elements can exist on any given page):
<div id="container">
<div id="sidebar">
</div><!-- #sidebar -->
<div id="main">
<div id="content">
</div><!-- #content -->
<div id="subscript">
</div><!-- #subscript -->
</div><!-- #main -->
</div><!-- #container -->
(I use these comments to be able to match closing tags with their counterpart, feel free to omit them.)
Now all you have to do is float the elements according to your needs:
#container {
overflow: hidden; /* don't collapse (floated children) */
width: 960px; /* fixed width for entire site */
}
#sidebar {
float: left; /* floating to the left in #container */
height: 200px; /* fixed height */
width: 320px; /* fixed width */
}
#main {
float: right; /* floating to the right of #container */
overflow: hidden; /* don't collapse (floated children) */
width: 640px; /* width of #container - width of #sidebar */
}
#content {
/* you shouldn't even need rules for this one */
}
#subscript {
float: left; /* floated to be only as wide as needed for content */
}
div
s are block elements, so unless they are either floated or have a fixed width, they take up all available space (see #content
).
Now floated elements on the other hand don't have a height, so their parent container would just collapse (i.e. you wouldn't be able to fill the whitespace-areas with a color with #container { background: red }
. To prevent #container
from collapsing, overflow: hidden
is required.
Basically, every time you float an element somewhere on your page, its parent container should have overflow: hidden
(see #container
and #main
).
Obviously, you would have to change the dimensions according to your needs.