I have been going through CSS Positions articles on Alistapart. Below snippet caught my attention and couldn't fathom the theory behind.
Below html/css shows two boxes one over other. But if I change the position of #box_1 to absolute, then #box_2 overlap #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>
How does the position of another box (box_1) affects position of a different/sibling div(box_2). Isn't 'absolute' should always absolute only to immediate non-static parent?
In the above css (with "position: relative;" in box_1), if I add "top: 0;" to #box_2, then box_2 appears to overlap again. Why does this happens?