DIV绝对定位在IE中不起作用

时间:2011-12-28 08:17:20

标签: css internet-explorer html css-position

以下代码在IE中不起作用。尽管DIV设置为left:0pxright:0px,但DIV并未跨越整个页面。根据调试器,Body元素的宽度很大。

为什么?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
    <div align="center" style="position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px; background-color: red">
            Some text

    </div>
</body>
</html>

3 个答案:

答案 0 :(得分:0)

如果你想使用整个页面。使用width:100%height:100%

答案 1 :(得分:0)

哟不能使用“left:0; right:0;”左侧或右侧,同一容器中的顶部底部相同。

使用此

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
    <body>
   <div align="center" style="position: absolute; left: 0; top: 0; background-color: red">
        Some text

   </div>
</body>
</html>

答案 2 :(得分:0)

实际上,不需要保证金。它也在IE中工作!

 position: absolute; width:100%;height:100%;background-color: red;
相关问题