【发布时间】:2013-02-12 08:20:06
【问题描述】:
我一直在经历CSS Positions articles on Alistapart。下面的 sn-p 引起了我的注意,无法理解背后的理论。
下面的 html/css 显示两个框并排。但是如果我将#box_1 的位置改为绝对位置,那么#box_2 会与#box_1 重叠。
<!DOCTYPE html >
<html lang="en">
<head>
<style>
#box_1 {
position: relative;
width: 200px;
height: 200px;
background: #ee3e64;
}
#box_2 {
position: absolute;
width: 200px;
height: 200px;
background: #44accf;
}
</style>
</head>
<body>
<div id="box_1"></div>
<div id="box_2"></div>
</body>
</html>
另一个框 (box_1) 的位置如何影响不同/兄弟 div(box_2) 的位置。 'absolute' 不应该永远只对直接的非静态父级是绝对的吗?
在上面的 css 中(在 box_1 中带有“position: relative;”),如果我添加“top: 0;”到 #box_2,然后 box_2 似乎再次重叠。为什么会这样?
【问题讨论】: