I certainly did not originate this method of creating a two column layout, but I will summarize it for you. Step one: create a wrapper or container div and give it a CSS rule: position:relative.
I’m temporarily ignoring the need for headers and footers. You can adjust for them. Step two: position the first div (we’ll call it #nav) using position:absolute. The numbers you use for top and left determine whether this column will be on the right or the left side of your page. Give the div a suitable width for your navigation.
Step three: Use a margin to create a second column with another div (we’ll call it #content). If the nav is on the left, use a wide margin-left. If the nav is on the right, use a wide margin-right. Assign a width that allows for the nav.
7 thoughts on “Tip: Three steps to a two column CSS layout”
Why is position:relative used for wrapper div?
Absolutely positioned DIVs can line up inside a container DIV defined as relative. The absolutely positioned divs still move up and down on the page in response to font-size changes and their position in relation to each other.
There are other ways to create a similar layout using floats. But floats have their own set of issues and this layout avoids them. That’s what I found interesting about this way of doing it.
Explanation re use of position:relative is excellent. Thank you so much
What if you want two columns that automatically arrange the text so that it wraps to the next column and ends up even height on both sides? Is that doable?
Yes, it is possible but not with the layout described in this post. Check this info at the W3C: http://www.w3.org/TR/css3-multicol/
Thank you for the link! Very thorough information on columns – a little overwhelming, but I will read it and see what I can learn…
7. Filling columns
There are two strategies for filling columns: columns can either be balanced, or not. If columns are balanced, UAs should minimize the variation in column length. Otherwise, columns are filled sequentially and some columns may end up partially filled, or with no content at all. In any case, the user agent should try to honor the ‘widows’ and ‘orphans’ properties.
Value: auto | balance