August 22, 2006
I can't believe that took as long as it did

I finally found out how to center divs on a page. I feel so stupid for not finding it earlier:

Max Design - CSS Centering - fun for all!

Theoretically, you should be able to apply auto margins to the left and right of the containing block and it should center on the page.

The W3C Visual formatting model states: "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."

So, a containing block should be able to be centered using the following rules:

margin-left: auto;
margin-right: auto;
width: 50em;

Posted by illovich at August 22, 2006 01:39 PM
Post a comment

Email Address:



Remember info?