Grow your CSS skills. Land your dream job.

Forced centering in IE

  • # July 22, 2008 at 6:24 pm

    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.

    # July 22, 2008 at 6:40 pm

    we need to see the html and css to see whats going on

    # July 22, 2008 at 7:04 pm
    "chazzwick" wrote:
    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.

    box
    # July 23, 2008 at 4:40 am

    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.

    # July 23, 2008 at 12:07 pm
    "box" wrote:
    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.

    # July 25, 2008 at 5:56 am

    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.

    box
    # July 25, 2008 at 2:20 pm
    "Edwin" wrote:
    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.

    # July 26, 2008 at 5:35 pm

    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. :?:

    pab
    # July 26, 2008 at 6:17 pm

    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

    box
    # July 27, 2008 at 12:20 pm

    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.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".