How to center HTML element in CSS

It's easy to center an element, for firefox and safari, we only need to specify the width and margin left and right set to auto. However, you will need to specify text-align to center in the parent element for IE.

CSS

body {
	text-align:center;	/* for ie	*/
}

#container {
	width:800px;
	margin:0 auto;	
	text-align:left;
}

Share the love

Leave a Comment

Please keep in mind that comments are moderated and rel="nofollow" is in use. You can use [code][/code] if you want to write codes. Don't spam us :) Thanks!

Advertisement