@@ -1077,28 +1077,83 @@ Style Containment</h3>
10771077 </wpt>
10781078
10791079 <div class=example>
1080- As 'counter-increment' is scoped to an element's subtree,
1081- the first use of it within the subtree acts as if the named counter were set to 0 at the scoping element,
1082- regardless of whether the counter had been used outside the scoping element.
1083- Any increments made within the subtree have no effect on counters of the same name outside the scoping element.
1084- However, the ''content/counter()'' and ''content/counters()'' value of the 'content' property is not itself scoped,
1085- and can refer to counters established outside of the subtree.
1086- Therefore, the following code results in <q><samp> 1 1.2</samp></q> being displayed:
1087- <pre><code highlight=markup>
1088- <div></div>
1089- </code></pre>
1090- <pre><code highlight=css>
1091- div {
1092- contain: style;
1093- counter-increment: n;
1094- }
1095- div::before, div::after {
1096- content: counters(n, '.' ) " ";
1097- }
1098- div::after {
1099- counter-increment: n 2;
1100- }
1101- </code></pre>
1080+ As 'counter-increment' is scoped to an element's subtree,
1081+ the first use of it within the subtree
1082+ creates a fresh counter,
1083+ regardless of whether the counter had been used outside the scoping element.
1084+ Any increments made within the subtree have no effect on counters of the same name outside the scoping element.
1085+ However, the ''content/counter()'' and ''content/counters()'' value of the 'content' property is not itself scoped,
1086+ and can refer to counters established outside of the subtree.
1087+
1088+ For example, the following markup and style:
1089+
1090+ <xmp highlight=markup>
1091+ <div>
1092+ <div style="contain: style;">
1093+ <div></div>
1094+ <div></div>
1095+ </div>
1096+ <div>
1097+ <div></div>
1098+ <div></div>
1099+ </div>
1100+ </div>
1101+ </xmp>
1102+
1103+ <pre highlight=css>
1104+ body {
1105+ counter-reset: foo;
1106+ }
1107+ div {
1108+ counter-increment: foo;
1109+
1110+ /* and to help observe nesting properly */
1111+ margin: .2em;
1112+ padding: .2em;
1113+ background: #0001;
1114+ }
1115+ div::before {
1116+ content: counters(foo, ".");
1117+ }
1118+ </pre>
1119+
1120+ Will render like:
1121+
1122+ <div id="scoped-counter-example">
1123+ <div> 1
1124+ <div style="contain: style;"> 2
1125+ <div> 2.1</div>
1126+ <div> 2.2</div>
1127+ </div>
1128+ <div> 3
1129+ <div> 4</div>
1130+ <div> 5</div>
1131+ </div>
1132+ </div>
1133+ </div>
1134+
1135+ <style>
1136+ #scoped-counter-example div {
1137+ margin: .2em;
1138+ padding: .2em;
1139+ background: #0001;
1140+ }
1141+ </style>
1142+
1143+ Here, the style-contained element still interacts with the ''foo'' counter normally,
1144+ incrementing it to 2.
1145+ Its ''::before'' pseudo-element,
1146+ which is effectively a child and thus within the containment boundary,
1147+ can still see that counter normally,
1148+ and thus will render the string "<code> 2</code> ".
1149+
1150+ Later siblings of the style-contained element don't see anything that goes on within the boundary,
1151+ so they increment the ''foo'' counter to 3 and beyond.
1152+
1153+ Within the containment, however,
1154+ the descendant divs aren't allowed to modify the value of the outside counter,
1155+ so instead they'll create a fresh (nested) ''foo'' counter
1156+ when they attempt to increment it.
11021157 </div>
11031158
11041159
0 commit comments