The fixing and the positioning are two separate things. They're positioned the same as absolutely positioned elements: relative to their containing block. But in contrast with absolutely positioned elements, they remain fixed to that position with respect to the viewport (i.e. they don't move when scrolling):
http://www.w3.org/TR/CSS2/visuren.html#propdef-position
The box's position is calculated according to the 'absolute' model, but in addition, the box is fixed with respect to some reference.
Positioning
The definition of containing block says:
If the element has 'position: fixed', the containing block is established by the viewport in the case of continuous media (...)
and
If the element has 'position: absolute', the containing block is established by the nearest ancestor with a 'position' of 'absolute', 'relative' or 'fixed' (...)
which suggests that while their positioning algorithm is the same (they're both positioned relative to their containing block), the containing block for fixed elements is always the viewport, in contrast with absolutely positioned elements, so they should be positioned relative to that and not to any absolutely or fixed-positioned elements.
And as a matter of fact, that is indeed the case. For example, if you add top: 20px
to .fixed
, both divs will be positioned 20 pixels from the top of the viewport. The nested fixed div does not get positioned 20 pixels down from the top of its parent.
The reason you're not seeing that in this case is because you're not actually setting any of the left/top/right/bottom properties, so their positions are determined by the position they would have in the flow (their "static position"), which as my first quote said, is done according to the absolute model.