Style Sheets
  Home arrow Style Sheets arrow Page 3 - Using Auto Margins with a Liquid Layout to...
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 a Liquid Layout to Center DIVs with CSS
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2009-04-09

    Table of Contents:
  • Using Auto Margins with a Liquid Layout to Center DIVs with CSS
  • Getting started using auto-margins with a liquid design
  • Working with CSS auto-margins
  • Merging the presentation and structural layers into one single file

  • 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 a Liquid Layout to Center DIVs with CSS - Working with CSS auto-margins


    (Page 3 of 4 )

    In the previous segment, I built a basic web page to help demonstrate how easy it is to create a fully-centered liquid layout using auto-margins. Having at our disposal the structural markup of the page in question, it’s time to add to it a set of CSS styles which will be responsible for constructing the centered layout. Essentially, the styles required to accomplish this task are the following:


    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,#footer{

    padding: 10px;

    background: #ffc;

    }

    #wrapper{

    width: 70%;

    margin-left: auto;

    margin-right: auto;

    }

    #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;

    }

    #maincol{

    clear: both;

    padding: 10px;

    background: #fff;

    }


    As shown before, the above group of CSS styles permits us to quickly build a centered web page layout, thanks to the functionality provided by auto-margins. In this case, you should notice that the main wrapper DIV has been assigned a width of 70%, while its respective left and right margins have been declared with a value of “auto.”

    So far, so good, right? At this point, you hopefully grasped the logic that stands behind building centered layouts by utilizing CSS auto-margins. Next, I will simply group the CSS styles coded before with the previous structural markup to complete the development of this centered web page design.

    To learn the full details of this process, please click on the link that appears below and read the following section.

    More Style Sheets Articles
    More By Alejandro Gervasio


       · This part of the series discusses how to construct an elastic, fully-centered web...
       · I don't see how this article is different than the previous. The ONLY difference...
       · Well, that’s exactly the difference: the previous article shows how to use CSS...
     

    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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek