Centering DIV with IE

Viewed 41385

I am trying to center a DIV, with "margin:auto" . It works fine with Chrome and FF but the following code does not center the DIV with IE:

CSS

#container {
 margin:auto;
 width:950px;
 height:50px;
 background:#000;
}

HTML

<div id="container"></div>

What am I doing wrong?

Thanks,

Joel


Edit (full HTML/CSS code):

<html>
<head>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.2.0/build/cssreset/reset-min.css">
<style>

#container {
 margin: 0 auto; 
 width:950px;
 height:50px;
 background:#000;
}
</style>
</head>
<body>
<div id="container"></div>
</body>
</html>
8 Answers

This worked for me with regards with the IE centering bug:

<div style="margin-left: auto; margin-right: auto; width: 50%;">
      <div style="text-align: left; margin: 1em auto; width: 50%;">
       

          <form action="/action_page.php">
            First name:<br>
            <input type="text" name="firstname" value="Tom">
            <br>
            Last name:<br>
            <input type="text" name="lastname" value="Cruise">
            <br><br>
            <input type="submit" value="Submit">
          </form> 

      </div>
</div>

Related