The Centering Cheat
If you've converted to valid XHTML, you'll have probably realised by now that the <center> tag has been deprecated (is no longer valid). No worries, this is easy to get 'round with a bit of CSS. First, give all the elements you want centered a class of something like "centered", like so:
<img src="images/header.gif" class="centered" />
Then — you can customise that class with CSS:
.centered {
margin: 0 auto 0 auto;
}
This assigns an automatic margin to both the left and right side, centering the object. Don't forget: you can shorten margin: 0 auto 0 auto; to margin: 0 auto; — read more on my Shortening CSS Code tutorial.
Note: If you're using the center cheat trick to center a top-level block element or a 'container' which will contain the rest of your coding, you must add text-align: center; to the body selector of the stylesheet. This is because some versions of Microsoft Internet Explorer and some older browsers do not support top-level element centering.
Tags:
css, tip,
Last Updated On: 24th February 06 by Jem
Bookmark At: StumbleUpon, Digg

Handy Stuff
Downloads
Friends of 'TT'
Resources