views:

399

answers:

3

My website passes both validation for both XHTML and CSS. It looks fine in Firefox, Chrome, Safari, Opera, even IE 6 (alas, not IE 5.5 but who cares?). Why then, would everything be pushed all the way to the left in IE 7? Any suggestions would be much appreciated.

+2  A: 

When i make a centered page i do the following;

set width for the "page"-div and fix margins and center the content in the body.

#page {
  width: 900px;
  margin: 0 auto;
  text-align: left;
}

body {
  text-align: center;
}

Has always worked fine for me in all browsers...

ullmark
I don't really understand why you use relative positioning on the page-div...
ullmark
Using relative positioning on div#page allows child elements to be positioned absolutely relative to the div rather than the window.
Mark Hurd
This did it... thanks!
Daniel Schaffer
A: 

Put another div around everything in the <body> and set your margin and width styles on that div, rather than the body itself. Set text-align: center; on <body> as well.

<body> <!-- text-align: center -->
    <div id="container"> <!-- width 960px, margin 30px auto, text-align: left, position: relative -->
        <div id="nav"></div>
        <div id="page"></div>
        <div id="preload"></div>
    </div>
</body>
Mark Hurd
A: 

It's borked because you do positioning on body/html elements which is plain wrong and will never look the same on all the browsers. See: http://www.sitepoint.com/blogs/2009/02/11/styling-the-html-and-body-elements/

Just use wrapper elements - NEVER position the body.

ionelmc
I'm confused... you say to NOT use styling on the body element, but then you post an article that says exactly the opposite... Besides, I wasn't positioning the body itself.
Daniel Schaffer