开发者

div not centering in compatibility mode

When IE8 is "normal" standards compliant mode the html and css belo开发者_如何学Gow does what it should and properly centers the red div. However in compatibility mode it does not get centered. Anyone here able to explain why and suggest an alternative?

<html>
   <head><title>test</title></head>
<body>
    <div 
        style="position: absolute;
        margin-left: auto;
        margin-right: auto;
        left: 0;
        right: 0;
        top: 0;
        width: 900px;
        background-color: red"
    >
        test
    </div>
</body>
</html>


to make it working without the doctype just do this way:

style="position: absolute;
        margin-left: -450px;
        left: 50%;
        top: 0;
        width: 900px;
        background-color: red"


<!doctype html>
<html>
    <head>
        <title></title>
        <style>
div {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 300px;
    height: 300px;
    margin: -150px 0 0 -150px;
    background: navy;
}
        </style>
    </head>
    <body>
        <div></div>
    </body>
</html>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜