简体   繁体   中英

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>

IE is notorious for not working without proper doctypes .

Try adding the HTML5 one

<!DOCTYPE html>

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; 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM