LiveDieBleed.net These are the lies I have created…

2Jul/100

The centering cheat

Posted by Alvina

If you are using div’s to built your layouts than a good thing to know is how center it. Because of the many different browsers it can sometimes be a hassle to find out what works with which browser.

Now centering a div isn’t at all difficult. Normally in HTML you could easily use the<center> tag but in XHTML it’s deprecated. So, you may wonder how you’ll make it work in XHTML. All you need to do is add the following code to your CSS.


.centered{
margin: 0 auto;
}

If you wish to use the centering cheat in your layouts make sure to add the following in your CSS.


body{
text-align: center; //To make it work in IE
}
#containerdiv{
margin: 0 auto;
text-align: left; //To make the text start at left (or justify/right) instead of center) side again.
}

Now your layout should be centered in every browser!

Tagged as: No Comments