Style Sheets
  Home arrow Style Sheets arrow Page 3 - Using Auto Margins with Multiple Columns t...
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

Using Auto Margins with Multiple Columns to Center DIVs with CSS
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-04-16

    Table of Contents:
  • Using Auto Margins with Multiple Columns to Center DIVs with CSS
  • Building a centered web document layout with CSS auto-margins
  • Adding CSS styles to the previous (X)HTML page
  • Tying the CSS styles to the structural markup

  • 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


    Using Auto Margins with Multiple Columns to Center DIVs with CSS - Adding CSS styles to the previous (X)HTML page


    (Page 3 of 4 )

    In the prior section, I built a sample web document whose structure was made up of three primary columns, identified as "leftcol," "maincol" and "rightcol" respectively. Since this process doesn't bear any further discussion, I will now style these columns to construct a centric design.

    Basically, the CSS code that renders this layout is as follows:


    body{

    padding: 0;

    margin: 0;

    background: #999;

    }

    h2{

    margin: 0;

    font: bold 18px Arial, Helvetica, sans-serif;

    color: #000;

    }

    p{

    font: normal 12px Arial, Helvetica, sans-serif;

    color: #000;

    }

    #header{

    padding: 10px;

    background: #ffc;

    }

    #wrapper{

    width: 70%;

    margin-left: auto;

    margin-right: auto;

    background: #fff;

    }

    #navbar{

    padding: 10px;

    background: #fff;

    }

    #navbar ul{

    list-style: none;

    padding: 0;

    margin: 0;

    }

    #navbar li{

    display: inline;

    padding: 0;

    margin: 0;

    }

    #navbar a:link,#navbar a:visited{

    margin-left: 20px;

    font: normal 12px Arial, Helvetica, sans-serif;

    color: #000;

    text-align: center;

    text-decoration: none;

    }

    #navbar a:hover{

    background: #fc0;

    }

    #leftcol{

    float: left;

    width: 20%;

    padding: 10px;

    }

    #maincol{

    float: left;

    width: 50%;

    padding: 10px;

    }

    #rightcol{

    float: right;

    width: 20%;

    padding: 10px;

    }

    #footer{

    clear: both;

    padding: 10px;

    background: #ffc;

    }


    Other than properly positioning the main columns of the web page that you saw before, the above CSS styles show in a nutshell how useful auto-margins can really be for centering each of these containers in one single step.

    In this case, the DIV identified as "wrapper" is actually the element responsible for achieving the centered positioning, since a value of "auto" has been assigned to its respective left and right margins.

    Okay, do you now realize how easy it is to create a multi-column, centered layout with CSS auto-margins? I guess you do! Nevertheless, the CSS styles previously coded must be attached to the structural markup of the pertinent web page.

    Therefore, if you wish to learn how this task will be carried out, read the following section. It's only one click away.

    More Style Sheets Articles
    More By Alejandro Gervasio


       · This tutorial shows how to expand the use of CSS auto-margins, in order to build a...
     

    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