Forum Moderators: open

Message Too Old, No Replies

Page centering on IE7

         

darrenyeats

5:58 pm on May 27, 2008 (gmt 0)

10+ Year Member



Hi All,
I have been knocking my head against a brick wall. It's easy to get the whole page centered using every browser known to man (I've tested Firefox, Konqueror, Epiphany, Safari 1 & 3, IE6) but not on IE7!

I used CSS and I'm using 'margin-left: auto;' and 'margin-right: auto'.

I've tried using the above in an enclosing <div>, but it didn't help.

Is there a simple incantation that will work on ALL browsers INCLUDING IE7? I am sure the solution is very simple once you know how.

Many many thanks! Yours frustratedly,
Darren

Zipper

6:57 pm on May 27, 2008 (gmt 0)

10+ Year Member



Are you using a DocType? It's good practice to use one to deal with cross-compatibility issues.

poppyrich

12:07 am on May 28, 2008 (gmt 0)

10+ Year Member



There's always the ever-faithful CENTER tag when all else fails.
My philosophy is: use what works to get it out the door - if you find a better solution later on, go back and change it then.

redwall_hp

3:37 am on May 28, 2008 (gmt 0)

10+ Year Member



IE tends to ignore the margin:auto thingy. Here's the hack you want:


#wrapper {
margin-right:auto;
margin-left:auto;
text-align:center;
}
#thecenteredelement {
width:900px;
text-align:left;
}

Voila, centered.

darrenyeats

10:34 am on May 28, 2008 (gmt 0)

10+ Year Member



Dear redwall_hp, the #wrapper, #thecenteredelement style sheet you provided doesn't seem to work for Firefox...the page just aligns left. If I change it to center then it fixes at 450px.

I tried the <center> tag around the top <div> and it works! Isn't this supposed to be deprecated? That's why I wasn't using it! However, as poppyrich says if it works go with it and try to find a better way at your leisure. What's more it seems to still work when I use <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> ... interesting.

Thanks to all.
Darren