tags:

views:

85

answers:

5

I have the following defined in my css file:

body  {
    text-align: center;
    float: right;
    position: fixed;
}
.twoColFixRtHdr #container {
    width: 780px;
    margin: 0 auto;
    border: 1px solid #000000;
    text-align: left;
}

and I have my HTML defined as follows:

<body class="twoColFixRtHdr">
  <div id="container">
    <div id="header">

The problem is, in IE (all versions I've been able to check) center the content of the page, but in Firefox, it's left-aligned. I know that text-align:center will center the content of the element, but not the element itself, so you have to nest your content, which is what the extra div is for. But I must be missing something about the differences between IE and Firefox in terms of how it renders this tag.

Any ideas? You can look at the site: http://www.solar-fit.ca

A: 

How about putting margin: 0px auto; in body ?

Joy Dutta
Sorry, that's also there. I trimmed the css. I'm adding more info to the question now.
Elie
+1  A: 

You tried this yet?

#container{
  width: 780px ;
  margin-left: auto ;
  margin-right: auto ;
}

You shouldn't need the nested div with this approach. According to the source ...

"The code above has been tested with IE 6, 7, Firefox, Opera and Safari."

JohnFx
yeah, I just did. Didn't seem to make any difference.
Elie
A: 

Not sure about the cause, but a fix is putting IE into standards mode via a DOCTYPE, e.g.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<style type="text/css">
    body  {
        text-align: center;
        float: right;
        position: fixed;
    }
    .twoColFixRtHdr #container {
        width: 780px;
        margin: 0 auto;
        border: 1px solid #000000;
        text-align: left;
    }
</style>
</head>
<body class="twoColFixRtHdr">
  <div id="container">
    <div id="header">
    Some text goes here
    </div>
  </div>
</body>
</html>
Justin Grant
But in IE it displays correctly! Why would I want to change that?
Elie
What is the desired result? Sorry I assumed that the firefox result was the one you wanted.
Justin Grant
+1  A: 

these two cause the problem

body -> float: right; position: fixed;

remove those

Moak
Now it's right aligned instead of centered. Which I suppose helps, since it was left aligned before. Let me try changing float to center.
Elie
There we go - deleted the wrong line. Thanks!
Elie
Remove 'text-align: center' too .. as it's doing nothing to centre your container. The centring is being carried out by 'margin: 0 auto;'
codeinthehole
@codinthehole: the text-align: center; is an IE fix
Moak
A: 

Remove the float and position properties from the body rule and add 100% width.

body { text-align: center; width: 100% }
Andrew Mullins