|
| 1 | +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | +<html lang="en"> |
| 3 | +<!-- $Id: zindex.src,v 2.1 2003-08-20 16:38:44 bbos Exp $ --> |
| 4 | +<HEAD> |
| 5 | +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| 6 | +<TITLE>Stacking Contexts</TITLE> |
| 7 | +</HEAD> |
| 8 | +<BODY> |
| 9 | +<ins>This entire chapter</ins> |
| 10 | +<H1>Stacking Contexts</H1> |
| 11 | + |
| 12 | +<p>This chapter defines the CSS2.1 painting order in more detail than |
| 13 | +described in the rest of the specification.</p> |
| 14 | + |
| 15 | +<h2>Definitions</h2> |
| 16 | + |
| 17 | +<dl> |
| 18 | +<dt>Tree Order</dt> |
| 19 | +<dd>Preorder depth-first traversal of the <em>rendering</em> tree, in logical |
| 20 | +(not visual) order for bidirectional content, after taking into |
| 21 | +account properties that move boxes around such as the 'run-in' value |
| 22 | +of 'display'.</dd> |
| 23 | + |
| 24 | +<dt>Element</dt> |
| 25 | +<dd>In this description, "element" refers to both actual elements and |
| 26 | +pseudo-elements. Pseudo-elements and anonymous boxes are treated as |
| 27 | +descendants in the appropriate places. For example, an outside list |
| 28 | +marker comes before an adjacent ':before' box in the line box, which |
| 29 | +comes before the content of the box, and so forth.</dd> |
| 30 | +</dl> |
| 31 | + |
| 32 | +<h2>Painting order</h2> |
| 33 | + |
| 34 | +<p>The bottom of the stack is the furthest from the user, the top of the |
| 35 | +stack is the nearest to the user:</p> |
| 36 | + |
| 37 | +<pre> |
| 38 | + | | | | |
| 39 | + | | | | ⇦ ☻ |
| 40 | + | | | user |
| 41 | + z-index: canvas -1 0 1 2 |
| 42 | +</pre> |
| 43 | + |
| 44 | +<p>The stacking context background and most negative positioned |
| 45 | +stacking contexts are at the bottom of the stack, while the most |
| 46 | +positive positioned stacking contexts are at the top of the stack.</p> |
| 47 | + |
| 48 | +<p>The canvas is transparent if contained within another, and given a |
| 49 | +UA-defined color if it is not. It is infinite in extent and contains |
| 50 | +the root element. Initially, the viewport is anchored with its top |
| 51 | +left corner at the canvas origin.</p> |
| 52 | + |
| 53 | +<p>The stacking order for an element generating a stacking context (see |
| 54 | +the 'z-index' property) is:</p> |
| 55 | + |
| 56 | +<ol> |
| 57 | +<li> If the element is a root element: |
| 58 | +<ol> |
| 59 | +<li> background color of element over the entire canvas. |
| 60 | +<li> background image of element, unclipped, painted at the origin |
| 61 | + that would be used if it was painted for the root element. |
| 62 | +</ol> |
| 63 | +<li>If the element is a block, list-item, or other block equivalent: |
| 64 | +<ol> |
| 65 | +<li> background color of element unless it is the root element. |
| 66 | +<li> background image of element unless it is the root element. |
| 67 | +<li> border of element. |
| 68 | +</ol> |
| 69 | + Otherwise, if the element is a block level table: |
| 70 | +<ol> |
| 71 | +<li> table backgrounds (color then image) unless it is the root element. |
| 72 | +<li> column group backgrounds (color then image). |
| 73 | +<li> column backgrounds (color then image). |
| 74 | +<li> row group backgrounds (color then image). |
| 75 | +<li> row backgrounds (color then image). |
| 76 | +<li> cell backgrounds (color then image). |
| 77 | +<li> all table borders (in tree order for separated borders). |
| 78 | +</ol> |
| 79 | +<li>Stacking contexts formed by positioned descendants with negative |
| 80 | + z-indices (excluding 0) in z-index order (most negative first) |
| 81 | + then tree order. |
| 82 | +<li>For all its in-flow, non-positioned, block-level descendants in |
| 83 | + tree order: If the element is a block, list-item, or other block |
| 84 | + equivalent: |
| 85 | +<ol> |
| 86 | +<li> background color of element. |
| 87 | +<li> background image of element. |
| 88 | +<li> border of element. |
| 89 | +</ol> |
| 90 | + Otherwise, the element is a table: |
| 91 | +<ol> |
| 92 | +<li> table backgrounds (color then image). |
| 93 | +<li> column group backgrounds (color then image). |
| 94 | +<li> column backgrounds (color then image). |
| 95 | +<li> row group backgrounds (color then image). |
| 96 | +<li> row backgrounds (color then image). |
| 97 | +<li> cell backgrounds (color then image). |
| 98 | +<li> all table borders (in tree order for separated borders). |
| 99 | +</ol> |
| 100 | +<li>All floating descendants, in tree order. For each one of these, |
| 101 | + treat the element as if it created a new stacking context, but any |
| 102 | + descendants which actually create a new stacking context should be |
| 103 | + considered part of the parent stacking context, not this new one. |
| 104 | + |
| 105 | +<li>First for the element, then for all its in-flow, non-positioned, |
| 106 | + block-level descendants in tree order: |
| 107 | +<ol> |
| 108 | +<li> For each element in each line box of the element, if any, or |
| 109 | + if the element is inline-level (note that all elements in line |
| 110 | + boxes are forcably inline-level), on a per-line-box basis: |
| 111 | +<ol> |
| 112 | +<li> Background color of element. |
| 113 | +<li> Background image of element. |
| 114 | +<li> Border of element. |
| 115 | +<li> For inline elements: |
| 116 | +<ol> |
| 117 | +<li> Underline of element. |
| 118 | +<li> Overline of element. |
| 119 | +<li> Text of element. |
| 120 | +<li> Then all the element's in-flow, non-positioned, |
| 121 | + inline-level descendants, including anonymous |
| 122 | + inline elements generated for text nodes inside |
| 123 | + the element, in tree order: |
| 124 | +<ol> |
| 125 | +<li> Jump to step 6.1 for this element. |
| 126 | +</ol> |
| 127 | +<li> Line-through of element. |
| 128 | +</ol> |
| 129 | + For inline-block and inline-table elements: |
| 130 | +<ol> |
| 131 | +<li> For each one of these, treat the element as if it |
| 132 | + created a new stacking context, but any |
| 133 | + descendants which actually create a new stacking |
| 134 | + context should be considered part of the parent |
| 135 | + stacking context, not this new one. |
| 136 | +</ol> |
| 137 | + For inline-level replaced elements: |
| 138 | +<ol> |
| 139 | +<li> The replaced content, atomically. |
| 140 | +</ol> |
| 141 | +<li> Optionally, the outline of the element (see 9 below). |
| 142 | +</ol> |
| 143 | +<li> Otherwise, if the element is a block-level replaced element, |
| 144 | + then the replaced content, atomically. |
| 145 | +<li> Optionally, if the element is block-level, the outline of the |
| 146 | + element (see 9 below). |
| 147 | +</ol> |
| 148 | +<li>All positioned descendants with 'z-index: auto' or 'z-index: 0', |
| 149 | + in tree order. For those with 'z-index: auto', treat the element |
| 150 | + as if it created a new stacking context, but any descendants which |
| 151 | + actually create a new stacking context should be considered part |
| 152 | + of the parent stacking context, not this new one. For those with |
| 153 | + 'z-index: 0', treat the stacking context generated atomically. |
| 154 | + |
| 155 | +<li>Stacking contexts formed by positioned descendants with z-indices |
| 156 | + greater than or equal to 1 in z-index order (smallest first) then |
| 157 | + tree order. |
| 158 | + |
| 159 | +<li>Finally, implementations that do not draw outlines in steps above |
| 160 | + must draw outlines from this stacking context at this stage. |
| 161 | +</ol> |
| 162 | + |
| 163 | +<h2>Notes</h2> |
| 164 | + |
| 165 | +<p>If the root element is a block-level element, its background is |
| 166 | +only painted once, over the whole canvas. If the root element is not a |
| 167 | +block-level element, then its background is painted twice, once for |
| 168 | +canvas, and once for the box(es) generated by the element.</p> |
| 169 | + |
| 170 | +<p>While the backgrounds of bidirectional inlines are painted in tree |
| 171 | +order, they are positioned in visual order. Since the positioning of |
| 172 | +inline backgrounds is unspecified in CSS2.1, the exact result of these |
| 173 | +two requirements is UA-defined. CSS3 may define this in more detail.</p> |
| 174 | + |
| 175 | +</BODY> |
| 176 | +</HTML> |
0 commit comments