user827329
user827329

Reputation:

IE9 center div block

Can somebody tell me how to make the work with IE9:

I am trying to make the "center" div to appear in the center.. It works fine with ff and chrome, but I have spend the last 1 hour trying to get it work with IE9. It keep going to the left!

The only way to make it work is by setting text-align to center on the parent container. Anybody knows any other way? More "proper"?

Thanks!

<html>
  <head>
    <style type="text/css">
      #center {
      width: 200px;
      border: 1px;
      margin: 0 auto;
      }
    </style>
  </head>
  <body>
    <div id="center">
      Hello World!
    </div>
  </body>
</html>
</code>

Upvotes: 4

Views: 9591

Answers (2)

Xavier
Xavier

Reputation: 8362

View the fiddle: http://jsfiddle.net/xavi3r/bGyPN/

Try removing </code> what is it referring to ?

<div id="center">
    Hello World
</div>

#center
{
     width:200px;
     margin:0 auto;
     border:1px solid #CCC; 
}

Upvotes: 1

Jason Gennaro
Jason Gennaro

Reputation: 34853

IE is notorious for not working without proper doctypes.

Try adding the HTML5 one

<!DOCTYPE html>

Upvotes: 28

Related Questions