Tuesday, October 6, 2009

Center align a div in IE 8

Usually when I want to center align a div on a page, I use margin:auto auto and set my width to a specific width, like 940px in my stylesheet. But, this does NOT work in IE 8. So to make that work, use

width:940px
height:100%
position:absolute
left:50% (to tell that your div should start in the middle of the page)
margin-left:-490px (half of your div size)

Thanks to this site

4 comments:

Anonymous said...

You need to add a vaild doctype for IE to centrally align a div using margin auto.

Anonymous said...

use this instead:

css-margin:auto;
html-

Anonymous said...

use this instead:

css-margin:auto;
html-
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

Lise said...

Thanks for sharing :)
/Lise