Center a page in IE?

Discussion in 'CSS' started by Leox Adir, Sep 15, 2007.

  1. #1
    I can't center the page in IE.
    Have tryed

    
    margin: 0 auto; 
    
    HTML:
    But that only works in FF.
    Please help me fast.

    Thanks,
    Leox
     
    Leox Adir, Sep 15, 2007 IP
  2. Xabber

    Xabber Active Member

    Messages:
    437
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #2
    You forgot to define your width.

    
    width: 750px;
    margin: auto;
    
    Code (markup):
     
    Xabber, Sep 15, 2007 IP
  3. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    width: 66%;
    margin-left: auto;
    margin-right: auto;
     
    le007, Sep 15, 2007 IP
  4. qube99

    qube99 Peon

    Messages:
    75
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Here's another method:

    
    body {
    	text-align:center;
    	}
    
    #Wrapper {
    	margin:0px auto;
    	text-align:left;
    	}
    
    Code (markup):
     
    qube99, Sep 15, 2007 IP
  5. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ^ for IE5.5 and under. I think 6 and know 7 obeys the margins.
     
    Stomme poes, Sep 15, 2007 IP
  6. Leox Adir

    Leox Adir Guest

    Messages:
    237
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    This is how i wrote:

    
    body {
    	font-family: Trebuchet MS, Verdana, Arial;
    	font-size: 12px;
    	width: 640px;
    	margin-left: auto;
        margin-right: auto;
       
    }
    
    HTML:
    and it doesn't work.
     
    Leox Adir, Sep 15, 2007 IP
  7. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Add what qube99 wrote.

    Older IE's don't obey margin auto. Broken box model.

    Even though you might not really want the text centered, this is IE5.5 (and 6?)'s way of centering stuff.

    To keep the text to the left (if that's what you want), look at what qube wrote for #Wrapper... this moves the text back while keeping the page centered in old IE.

    Try it.
     
    Stomme poes, Sep 15, 2007 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #8
    margin: 0 auto; works in IE6 if you are in standards compliant mode - text-align:center works for IE in quirks mode or IE 5.x

    I usually state both for the page wrapper on fixed width layouts, but say the heck with it on contents as I see little or no IE 5.x traffic anymore and they can live with a 'degraded' appearance. (if they can't live with it, they can upgrade to one of the free browsers that doesn't suck)

    Question: do you have a valid doctype without a XML prolog? Is it the first thing in the document with NOTHING before it, even blank lines being verboten?

    If the answer is no, you are in quirks mode and are going to spend hours if not weeks hacking around stuff for IE 6 that should only take a few seconds, minutes on the outside.
     
    deathshadow, Sep 16, 2007 IP
  9. Trapped

    Trapped Well-Known Member

    Messages:
    1,832
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    130
    #9
    This is the right method and the only way it will work in all browsers.
     
    Trapped, Sep 16, 2007 IP
  10. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #10
    If you want to support IE 5.x which most people don't anymore. If you don't care about IE 5.x, then you can safely just use the width and auto left/right margins on the body and be done with it.
     
    Dan Schulz, Sep 16, 2007 IP
  11. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #11
    Assuming you aren't in quirks mode ;)
     
    deathshadow, Sep 16, 2007 IP
  12. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #12
    As always. :)
     
    Dan Schulz, Sep 16, 2007 IP