Home arrow Resources arrow Simple CSS column layout

Simple CSS column layout

A lot of designers are currently struggling to accomplish page layout that was simple to achieve using tables but is frustratingly difficult (if not impossible) with CSS. The following example shows a simple method to display a mutli-column content layout without having to worry about complex floats, margins, and padding.

It all begins with a simple unordered list with a line item and div for each column. We assign an id selector to each item that may have individual CSS styles applied to it (eg id="column1"). Then add a style sheet class for all items that share formatting (eg: class="r_column").

  1. <ul>
  2. <li>
  3. <div class="r_column" id="column1">
  4. <p>First Column</p>
  5. </div>
  6. </li>
  7. <li>
  8. <div class="r_column" id="column2">
  9. <p>Second Column</p>
  10. </div>
  11. </li>
  12. <li>
  13. <div class="r_column" id="column3">
  14. <p>Third Column</p>
  15. </div>
  16. </li>
  17. </ul>

The real magic occurs in the CSS where we make the list appear horizontally rather than vertically. Because of differences in browsers we have to set the margin and padding explicitly. The rest is explained in the code below.

  1. ul {
  2. clear:both; // needed to clear the floated divs
  3. }
  4.  
  5. ul li {
  6. padding: 0; // removes spacing between items
  7. margin: 0; // removes spacing between items
  8. display: inline; // makes the list side by side
  9. list-style:none; // removes the bullet from the list
  10. }
  11.  
  12. div.r_column {
  13. margin: 0 5px; // set the space between items
  14. display: block; // needed to correctly render the div
  15. float:left; // make divs appear side by side
  16. width: 20em; // set the width of the column
  17. }

Put it all together and we get:


  • First Column

  • Second Column

  • Third Column



Now isn't that about as simple as you can get?

 
Add to:BlinkbitsAdd to:BlinklistAdd to:BlogmarksAdd to:Del.icio.usAdd to:DiggAdd to:DiigoAdd to:FolkdAdd to:FurlAdd to:GoogleAdd to:IcioAdd to:LinkarenaAdd to:Ma.GnoliaAdd to:NetscapeAdd to:NetvouzAdd to:NewsvineAdd to:OneviewAdd to:RedditAdd to:SimpyAdd to:SlashdotAdd to:SmarkingAdd to:SpurlAdd to:StumbleUponAdd to:TechnoratiAdd to:WebnewsAdd to:Mr. WongAdd to:YahooAdd to:YiggAdd to:Information
 
© Copyright 2007 Coda Graphic Design, San Francisco, California