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

Share this blog post:

4
Leave a Reply

avatar
4 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
AnonymousLise Recent comment authors

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
newest oldest most voted
Notify of
Lise
Guest

Thanks for sharing 🙂
/Lise

Anonymous
Guest
Anonymous

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&quot; >

Anonymous
Guest
Anonymous

use this instead:

css-margin:auto;
html-

Anonymous
Guest
Anonymous

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