Style Sheets
  Home arrow Style Sheets arrow Page 3 - Creating Three-Column Web Page Layous with...
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 
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

Creating Three-Column Web Page Layous with Negative Margins
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-09-03

    Table of Contents:
  • Creating Three-Column Web Page Layous with Negative Margins
  • A first step: a basic two-column web page layout
  • Building three-column web page layouts
  • Listing the full source code of the three-column web page design

  • 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


    Creating Three-Column Web Page Layous with Negative Margins - Building three-column web page layouts


    (Page 3 of 4 )

    If you found creating two-column web page layouts using negative margins a no-brainer process, then it's highly probable that you'll grasp in a snap how to implement the same approach to construct web documents comprised of three primary columns.

    How can this be done utilizing negative margins? Well, the answer to that specific question is actually much simpler than what you might think initially. Essentially, it's based on defining two lateral bars, which will be floated respectively to the left and the right sides of a web page, while the main column will be centered by specifying negative values for their "margin-left" and "margin-right" CSS properties.

    In addition, it's fair to mention that this main column will be wrapped by an additional container, as you saw in previous examples, meaning that the  negative margins will be applied directly to this container instead. Of course, the way that this approach works will be better understood by example, so take a look at the following CSS styles, which are responsible for building this three-column design through the use of negative margins.

    Here they are:


    /* style header section */

    #header{

    background: #ffc;

    }

    /* style navigation bar */

    #navbar{

    float: left;

    width: 300px;

    background: #ccc;

    }

    /* wraps up the main column */

    #wrapper{

    float: left;

    width: 100%;

    margin-left: -300px;

    margin-right: -300px;

    }

    /* style main column */

    #maincol{

    margin-right: 300px;

    margin-left: 300px;

    }

    /* style side column */

    #sidecol{

    float: right;

    width: 300px;

    background: #ccc;

    }

    /* style footer section */

    #footer{

    clear: both;

    background: #ffc;

    }

    As I said before, apart from styling the respective side bars of the web document, the above CSS code assigns two negative values to the left and right margins of the wrapping DIV that contain the main column, in this way centering it within the web document in question.

    The rest of the previous CSS styles are simply included with the purpose of styling the header and footer sections of the web page, so I assume that you won't have major problems understanding how they work.

    Well, at this point you hopefully grasped the logic that stands behind using negative margins to build a rudimentary three-column web page layout. Nonetheless, I must admit that the CSS styles listed above look pretty disconnected if they're not accompanied by the corresponding structural markup, right?

    Therefore, in the last section of this tutorial I'll be showing you a final example, where both the CSS styles and (X)HTML code are included in one single file to construct a consistent three-column web page layout.

    To see how this brand new sample file will look, jump ahead and read the next few lines.

    More Style Sheets Articles
    More By Alejandro Gervasio


       · This third installment of the series demonstrates how to use negative CSS margins...
       · Hi Alejandro,I have been playing with your 3-col CSS layout (many thanks for...
       · Thanks Martin for the comments on my CSS article. First off, negative CSS margins...
       · Hi Alejandro,Thanks for taking the time to reply. The frames issue is because at...
       · Hey Martin,If you’re getting more problems with your linked lists, try...
     

    STYLE SHEETS ARTICLES

    - Image Replacement CSS Techniques
    - Using BlueTrip`s Success, Notice and Error C...
    - More Uses for the Thin and Caps CSS Classes ...
    - Styling Definition Lists with the BlueTrip C...
    - Styling Unordered and Ordered HTML Lists wit...
    - Using the BlueTrip CSS Framework`s Thin and ...
    - Adding Borders to Web Page Columns with Blue...
    - Introducing the BlueTrip CSS Framework
    - Using a Background Grid to Assist Web Page L...
    - Extending the Rule Of Thirds for Web Page La...
    - A Two-Column Web Page Layout Based on the Ru...
    - Using the Rule Of Thirds for Web Page Layout
    - Swapping Columns Using the Divine Ratio for ...
    - Using the Golden Ratio in Liquid Web Page De...
    - Fundamental Design Principles for Web Page L...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek