Style Sheets
  Home arrow Style Sheets arrow Page 2 - Matching Web Page Columns with CSS
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

Matching Web Page Columns with CSS
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2007-07-18

    Table of Contents:
  • Matching Web Page Columns with CSS
  • Building a DIV-based web page layout with unleveled columns
  • Matching the heights of web page columns
  • Achieving a fully-balanced three-column web page layout

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Matching Web Page Columns with CSS - Building a DIV-based web page layout with unleveled columns


    (Page 2 of 4 )

    In accordance with the concepts deployed in the beginning of this article, before I proceed to show you how to keep the main columns of a given web document completely matched, first I'd like to develop an introductory example aimed at illustrating clearly the nature of the aforementioned issue.

    As you'll see in a few moments, the hands-on example that I plan to include here will be based upon building a basic web page comprised of the header, main, and footer sections, which will display its respective vertical columns completely unleveled.

    Having said that, now have a look at the following screen shot that precisely demonstrates this undesirable condition:

    As depicted by the above image, I built a sample web document which displays on the browser its main columns entirely unmatched. It's a pretty ugly effect, right? However, as you'll certainly know, this scenario is quite frequent when designing the front-end of a web site, at least in its first development stages.

    All right, now that you have a more accurate idea about the problems that might arise surrounding the display of unleveled columns included into a given web page, let me show you the corresponding CSS styles and structural markup that builds the web document depicted previously.

    The signature of this sample (X)HTML file looks like this:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-
    8859-1" />
    <style type="text/css">
    body{
       padding: 0;|
       margin: 0;
       background: #fff;
    }

    h2{
       margin: 0;
       font: bold 18px Arial, Helvetica, sans-serif;
       color: #000;      
    }

    p{
       font: normal 12px Arial, Helvetica, sans-serif;
       color: #000;      
    }

    #header{
       padding: 2%;
       background: #ffc;
    }

    #navbar{
       padding: 1% 2% 1% 2%;
       background: #fc0;
    }

    #navbar ul{
       list-style: none;
    }

    #navbar li{
       display: inline;
       padding-right: 4%;
    }

    #navbar a:link,#navbar a:visited{
       font: normal 12px Arial, Helvetica, sans-serif;
       color: #039;
       text-decoration: none;
    }

    #navbar a:hover{
       text-decoration: underline;
    }

    #leftcol{
       clear: both;
       float: left;
       width: 16%;
       padding: 2%;
       background: #eee;
    }

    #maincol{
       float: left;
       width: 55%;
       padding: 2%;
    }          

    #rightcol{
       float: right;
       width: 16%;
       padding: 2%;
       background: #eee;
    }

    #footer{
       clear: both;
       padding: 2%;
       background: #ffc;
    }
    </style>
    <title>Example of unleveled columns</title>
    </head>
    <body>
     
    <div id="header">
       
    <h2>This is the header section of the web page</h2>
       
    <p>Contents for header section go here. Contents for header
    section go here. Contents for header section go here. Contents
    for header section go here.</p>
     
    </div>
     
    <div id="navbar">
       
    <h2>This is the navigation bar of the web page</h2>
       
    <ul>
         
    <li><a href="#">Link 1</a></li>
         
    <li><a href="#">Link 2</a></li>
          
    <li><a href="#">Link 3</a></li>
         
    <li><a href="#">Link 4</a></li>
         
    <li><a href="#">Link 5</a></li>
         
    <li><a href="#">Link 6</a></li>
       
    </ul>
     
    </div>
     
    <div id="leftcol">
       
    <h2>This is the left column of the web page</h2>
       
    <p>Contents for left column go here. Contents for left column
    go here. Contents for left column go here. Contents for left
    column go here. Contents for left column go here. Contents for
    left column go here. Contents for left column go here. Contents
    for left column go here. Contents for left column go here.
    Contents for left column go here.</p>
      
    </div>
     
    <div id="maincol">
       
    <h2>This is the center column of the web page</h2>
       
    <p>Contents for center column go here. Contents for center
    column go here. Contents for center column go here. Contents for
    center column go here. Contents for center column go here.
    Contents for center column go here. Contents for center column go
    here. Contents for center column go here. Contents for center
    column go here. Contents for center column go here.</p>
     
    </div>
     
    <div id="rightcol">
       
    <h2>This is the right column of the web page</h2>
       
    <p>Contents for right column go here. Contents for right
    column go here. Contents for right column go here. Contents for
    right column go here. Contents for right column go here.</p>
     
    </div>
     
    <div id="footer">
       
    <h2>This is the footer section of the web page</h2>
       
    <p>Contents for footer section go here. Contents for footer
    section go here. Contents for footer section go here. Contents
    for footer section go here. Contents for footer section go
    here.</p>
     
    </div>
    </body>
    </html>

    As you can see, the prior (X)HTML file uses a few simple CSS styles and a basic structural markup to display a primitive web page, achieving the extremely popular three-column layout. In addition, you should notice that the layout in question is based on a liquid design, and that all the corresponding columns have been positioned in the web document by using the "float" CSS property. Pretty simple, right?

    Of course, as you'll possibly know, there are many ways to build a three-column web page layout like the one shown, but in this case I opted to use floating DIVs to illustrate the problem. And certainly, speaking of problems, you can see that the prior sample web page displays its main columns entirely unmatched, definitely an undesirable effect that makes it look pretty unprofessional.

    So far, so good, right? At this point, I provided you with a concrete example concerning the creation of a three-column web page layout, which obviously presents a serious problem, since the respective columns are shown completely unleveled.

    However, as you may have guessed, the aforementioned issue can be easily corrected by using only some basic CSS styles for matching the respective heights of the columns.

    Want to see how the previous sample web page will be modified to match its columns? Click on the link below and keep reading.

    More Style Sheets Articles
    More By Alejandro Gervasio


       · While the topic has been covered already by many web designers, this article shows a...
       · I am just a beginner so I am looking at all the tutorial that I can find. I found...
       · Hi Susie,Thank you for the kind words on my CSS article. It's good to know that...
       · Ok, but what if you put only one paragraph in "centerbar" container and set its...
       · Thanks for the comments on my article. It’s very easy to solve the issue you...
       · As a beginner I appreciate the effort you put into making this information...
       · Hi Ron,Thank you for the comments on my CSS article, and it’s good to know it’s...
       · Does this work with a floating div design as well? See, I made a basic floating...
       · Thanks for this wonderful article. It works like a charm.I was wondering though,...
       · Thanks for the comments on my article. Wit reference to your question, yes it’s...
       · Hi Brett,Thanks for the kind comments on my article. Regarding your question,...
     

    STYLE SHEETS ARTICLES

    - Improving the Visual Presentation of a CSS D...
    - Fixing Browser Incompatibilities in a CSS Dr...
    - Building Clean Drop-Down Menus with CSS
    - Creating Hybrid Web Page Layouts with Negati...
    - Creating Three-Column Web Page Layous with N...
    - Swapping Column Positions in Web Page Layout...
    - Creating Web Page Layouts with Negative Marg...
    - Creating Gradients for Individual Containers...
    - Creating Gradients for Web Page Headers with...
    - SEO Scrolling Frames Problem Solved
    - Building Cross-Browser Background Effects wi...
    - CSS: Pseudo
    - Using PNG Images to Build Background Effects
    - CSS: Continuing the Clarification of CSS Cla...
    - CSS: Top Secret Classification






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT