Home arrow Style Sheets arrow Page 3 - Building a Liquid Design with Evened Margins and Centered CSS DIVs
STYLE SHEETS

Building a Liquid Design with Evened Margins and Centered CSS DIVs


If you’re a web designer who wishes to learn how to build fully-centered web page layouts using CSS, you've come to the right place. Welcome to the final installment of a seven-part series on centering DIVs with CSS. This series shows you how to take advantage of the functionality provided by different DIV alignment techniques to construct centered web page designs, which can be incorporated into any existing site with minor effort.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
April 30, 2009
TABLE OF CONTENTS:
  1. · Building a Liquid Design with Evened Margins and Centered CSS DIVs
  2. · Constructing an elastic web page layout with evened CSS margins
  3. · Centering DIVs with evened CSS margins
  4. · Completing the development of the centered layout

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Building a Liquid Design with Evened Margins and Centered CSS DIVs - Centering DIVs with evened CSS margins
(Page 3 of 4 )

In the prior section I defined the structural markup of a sample web page, so the next step I'm going to take consists of coding a group of CSS styles, which will be tasked with constructing the pertinent centered layout, in this case by way of evened margins.

That being said, here's the definition corresponding to the CSS styles:


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{

margin-left: 20%;

margin-right: 20%;

}

#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 depicted above, it's actually very simple to build a liquid, centered design by using evened CSS margins. In this case, the DIV identified as "wrapper" is the element that really does the hard work, since a value of "20%" has been assigned equally to its left and right margins. In doing so, all of the other descendant elements will be centered on screen, thus achieving the desired design. Pretty easy to grasp, isn't it?

So far, so good. At this stage, you hopefully learned how to apply evened CSS margins for quickly constructing a centered web page design. So what's next? Well, if you're anything like me, you want to see how the previous CSS code can be tied to the corresponding markup of the sample web page.

Thus, in the final segment of this tutorial I'll be defining a brand new (X)HTML file, which will put these two layers to work together.

To see how this sample file will be created, please click on the link below and keep reading.


blog comments powered by Disqus
STYLE SHEETS ARTICLES

- CSS Combinators: Working with Child Combinat...
- CSS Combinators: Using General Siblings
- Intro to CSS Combinators
- CSS Semicircles and Web Page Headers
- Drawing Circular Shapes with CSS3 and Border...
- More CSS Pagination Link Templates
- CSS Pagination Links
- Animated CSS3 Image Gallery: Advanced Transi...
- CSS3 Animated Image Gallery: Transitions
- CSS3 Properties: Fixed Heights with box-sizi...
- CSS3 Properties: Altering Strokes and 3D Eff...
- CSS3 Properties: Text-Stroke
- CSS3 Transitions: Width and Height Properties
- Creating a Drop Down Menu in CSS3
- Intro to CSS Transitions

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials