Skip to content

Commit 3d96314

Browse files
committed
[css-nesting-1] adds relative order example with a tricky :is()
1 parent b77c58b commit 3d96314

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

css-nesting-1/Overview.bs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,61 @@ Mixing Nesting Rules and Declarations {#mixing}
567567
the relative order in the stylesheet of the applicable declarations
568568
determines which declaration "wins" the <a>cascade</a>.
569569

570+
<div class="example">
571+
For example, consider the following where the specificity is the same and the
572+
cascade is used for value resolution:
573+
574+
<pre class="lang-css">
575+
article {
576+
& .blue { color: blue; }
577+
& .red { color: red; }
578+
}
579+
580+
/* equivalent to
581+
article .blue { color: blue; }
582+
article .red { color: red; }
583+
*/
584+
</pre>
585+
586+
<pre class="lang-html">
587+
&#60;article&#62;
588+
&#60;div class="red blue"&#62;&#60;/div&#62;
589+
&#60;/article&#62;
590+
591+
/* div text color is red */
592+
</pre>
593+
594+
and this follow up:
595+
596+
<pre class="lang-css">
597+
article {
598+
& .blue, & #gotcha { color: blue; }
599+
& .red { color: red; }
600+
}
601+
602+
/* equivalent to
603+
article :is(.blue, #gotcha) {
604+
color: blue;
605+
}
606+
article .red { color: red; }
607+
*/
608+
</pre>
609+
610+
<pre class="lang-html">
611+
&#60;article&#62;
612+
&#60;div class="red blue"&#62;&#60;/div&#62;
613+
&#60;/article&#62;
614+
615+
/* div text color is blue */
616+
</pre>
617+
618+
specificities between ''.red'' and ''.blue''
619+
no longer match because the equivalent internal representation of the nesting
620+
uses '':is()'', which becomes the specificity of it's highest selector.
621+
The convenience of nesting ''#gotcha'' and ''.blue'' together has joined
622+
their specificity, affecting the resolve style, making the color blue.
623+
</div>
624+
570625

571626
CSS Object Model Modifications {#cssom}
572627
=======================================

0 commit comments

Comments
 (0)