My grasp of CSS positioning was solid until I stumbled upon this straightforward code snippet (also available in JSFiddle).
#outer {
/*position: absolute;*/
box-shadow: inset 0 0 3px red;
}
#inner {
box-shadow: inset 0 0 3px blue;
/*position: absolute;
left: 15px;*/
}
<p id="outer">outer
<p id="inner">inner</p>
</p>
What bewilders me are the following:
- If you remove the comment from the first
position: absolute;
rule, why does theouter
paragraph not overlay theinner
one? Since the outer paragraph lacks any non-static parent, it should be positioned with respect to the browser window, shouldn't it? - Uncommenting the first rule and then setting
position: absolute; left: 15px;
for theinner
paragraph causes the element to shift downwards. Why does this happen?