Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Because the two elements are each <strong>in-flow, non-positioned, block-level elements in the same stacking context</strong>.</p> <p>Two in-flow, non-positioned blocks aren't strictly "above" or "below" each other -- their <strong>contents and backgrounds stack separately</strong>.</p> <p>Adding <code>position: relative</code> will make an element positioned (with <code>z-index: auto</code>) and place it above non-positioned elements in the same stacking context: it will be rendered at step 8 in the painting algorithm below.</p> <hr> <p>If you read the CSS2 spec's <a href="http://www.w3.org/TR/CSS2/zindex.html" rel="nofollow">Elaborate description of Stacking Contexts</a> closely, you will see that this is correct behavior.</p> <p>In-flow, non-positioned, block-level elements within the same stacking context first have all their backgrounds rendered, then all their contents. Their backgrounds are above positioned elements with a negative <code>z-index</code> and below everything else.</p> <p>The relevant steps in the painting algorithm:</p> <blockquote> <p><ol> <li>...</li> <li>...</li> <li>...</li> <li>For all its in-flow, non-positioned, block-level descendants in tree order: If the element is a block, list-item, or other block equivalent: <ol> <li>background color of element.</li> <li>background image of element.</li> <li>border of element.</li> </ol></li> <li>...</li> <li>...</li> <li>... for all its in-flow, non-positioned, block-level descendants in tree order: <ol> <li>...</li> <li>... for each line box of that element: <ol> <li>For each box that is a child of that element, in that line box, in tree order: <ol> <li>...</li> <li>...</li> <li>...</li> <li>For inline elements: <ol> <li>For all the element's in-flow, non-positioned, inline-level children that are in this line box, and all runs of text inside the element that is on this line box, in tree order: <ol> <li>If this is a run of text, then: <ol> <li>...</li> <li>...</li> <li>the text.</li> <li>...</li> </ol></li> </ol></li> </ol></li> </ol></li> </ol></li> </ol></li> <li>...</li> <li>...</li> <li>...</li> </ol></p> </blockquote> <p>Floated and positioned elements are always "atomic" -- their backgrounds and contents will be rendered together in a single step (either step 3, 5, 8 or 9). But in-flow, non-positioned block elements within the same stacking context have all their backgrounds rendered (in step 4), then have all their contents rendered (in step 7).</p> <p>In this case, for in-flow, non-positioned sibling elements H1 and P (H1 before P in the tree), step 4 renders the H1 background and then the P background, then step 7 renders the H1 content and then the P content.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload