... CSS Centering fixed width layouts ...



• CSS Centering fixed-width layouts »»


Do you ever wonder how you can center a containing div?
The use of “tables” or “center” tag makes the job a lot easier, but it will fail validation.
Another way of doing this is using CSS stylesheet.

body{padding:0px; margin:0px; text-align:center;}

#div_container{margin-left: auto;margin-right: auto;width:800px;}

The only problem with the above solution is that “#div_container” will also have the text centered.
To overcome this problem you have to specify the “text-align” tag as below:

body{padding:0px; margin:0px; text-align:center;} #div_container{margin-left: auto;margin-right: auto;width:800px;<strong><font color="#ff0000">text-align:left</font></strong>;}

W3C Visual formatting model explains: “If both ‘margin-left’ and ‘margin-right’ are ‘auto’, their used values are equal.
This horizontally centers the element with respect to the edges of the containing block.”

 Bookmark with:            
Source: web-design-ireland | pub: 15 Oct 2007 by: Louie Eire Web Design | added: 26 Feb 2008 | cat: Css | views: 54 time/s
Related Articles...
Leave a Comment...
Name: *
Email: *
Comment: *
Security Code: security code
*
     Remember me:
Categories
Channels
Press Release