为什么绝对定位在这种情况下不起作用_它的顶部和左侧值

时间:2012-10-04 17:18:36

标签: absolute

我用css做了一些绝对的定位。但在以下情况中,为什么在 firstBox 中, top left 值会被忽略? (我想要100 px的顶部,并留在100px)。第二个框是正确的。

<html>
<head>
<title>Testing</title>
<style type="text/css">
#firstBox {
  color: white;
  width: 500px;
  padding: 1em;
  background: red;
  position::absolute;
  top:100px;
  left:100px;
 z-index:2;
}
#secondBox {
    color: white;
    width: 500px;
    padding: 1em;
    background: blue;
    position: absolute;
    top: 100px;
    left: 100px;
    z-index: 0;
}
</style>
</head>
<body>
<div id="firstBox"> The First Box! </div>
<div id="secondBox"> The Second Box! </div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

这是因为您position: absolute;使用 2冒号 #firstBox

My Fiddle