QuestenaPractice that shows what to review next
Question 10

Consider this nesting, where .outer has position: relative, .middle has position: static (the default), and .inner has position: absolute with top: 0 and left: 0. No ancestor uses transform, filter, or CSS containment. <div class='outer'><div class='middle'><div class='inner'></div></div></div> Which box does .inner position itself against?

  1. The padding box of .outer.Correct answer
  2. The padding box of .middle, since it is the element's direct parent.
  3. The content box of .outer.
  4. The viewport, because none of the ancestors is itself position: absolute.

Explanation

An absolutely positioned box is laid out against the nearest ancestor that is positioned — that is, whose position is anything other than static. .middle is static, so it is skipped entirely despite being the parent, and .outer, being relative, provides the containing block. The edges used are the padding edges, not the content edges, so .inner's top: 0 / left: 0 lands at the inside corner of .outer's padding, ignoring .outer's own padding values. If no positioned ancestor existed at all, the containing block would be the initial containing block (viewport-sized), not simply 'the viewport' as a live reference frame — which is what position: fixed uses.

Continue with this test

Start practice
Question 10: Consider this nesting, where .outer has position: relative,… · CSS Fundamentals Readiness Check · Questena