How to center a div box using CSS?

It is a common problem that the element doesn’t center properly. It’s very easy to fix this. Here is a sample html code.

<body>
	<div  id="pageWrapper">
	</div>
</body>

To let pageWrapper center align, we can use the following for Firefox:

#{
        margin:0 auto;
        width:980px;
}

But this doesn’t work for IE. To use under IE you can use the following css.

body{
       text-align:center;
}

Related posts: