treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Forced centering in IE

  • I am working on a new design and It is not centering in IE . It centers fine in Firefox, Safari, and Opera but not IE . Got any ideas of what the problem is.
  • we need to see the html and css to see whats going on
  • "chazzwick" said:
    we need to see the html and css to see whats going on


    I have everything within a page wrap.

    The HTML:

    <div id="page-wrap"> </div>

    The CSS :

    #page-wrap{
    width: 950px;
    margin:0 auto;
    }

    How's that.
  • Use a strict doctype - a transitional doctype forces IE6 into quirks mode and the margin:0 auto; is unrecognised. In strict (standards mode) your site should centre without problems.
  • "box" said:
    Use a strict doctype - a transitional doctype forces IE6 into quirks mode and the margin:0 auto; is unrecognised. In strict (standards mode) your site should centre without problems.


    You were write . I changed the doctype and my problem is now fixed. Thanks.
  • You could also add text-align:center; to the body and then set the text-align back to left in your page-wrap. I think that's maybe a better way to do it.
  • "Edwin" said:
    I think that's maybe a better way to do it.

    Why? It isn't necessary. All you end up doing is adding unnecessary extra CSS and in some cases having to add an extra div to your HTML as a page wrap. Not all layouts require a separate wrapper div in addition to the body element.
  • But I thought you already had a pagewrap and wanted it centered in IE6. It's a time ago I did it, but I thought this was the way how to do it. :?:
  • you also end up fixing IE4 IE5 by doing the text-align center on the body and text align left on the wrap

    that being said who still codes for IE4 & IE5
  • Using text-align:center; to force a web page to centre is a hack in my view and certainly not necessary for IE6 or later. For eariler IE's (for anyone suicidal enough to still build for them) then indeed you'll use the text-align:center; hack to centre your site via a conditional stylesheet. But really, anyone still using IE5.5 or earlier to browse the web will be well used to broken web sites ;) and the worst that would happen in those very old browsers is that the site will be left aligned, so still otherwise fully functional.