@@ -573,8 +573,8 @@ Mixing Nesting Rules and Declarations {#mixing}
573
573
574
574
<pre class="lang-css">
575
575
article {
576
- & .blue { color: blue; }
577
- & .red { color: red; }
576
+ & .blue { color: blue; } /* (0,1,1) */
577
+ & .red { color: red; } /* (0,1,1) */
578
578
}
579
579
580
580
/* equivalent to
@@ -588,22 +588,50 @@ Mixing Nesting Rules and Declarations {#mixing}
588
588
<div class="red blue"></div>
589
589
</article>
590
590
591
- /* div text color is red */
591
+ <!-- div text color is red -->
592
592
</pre>
593
593
594
- and this follow up:
594
+ The specificity of ''article .blue'' and ''article .red'' is (0,1,1).
595
+
596
+ Now consider this follow up which adds an ID selector:
597
+
598
+ <pre class="lang-css">
599
+ article {
600
+ & .blue, & #gotcha { color: blue; } /* (1,1,1) */
601
+ & .red { color: red; } /* (0,1,1) */
602
+ }
603
+
604
+ /* equivalent to
605
+ article :is(.blue, #gotcha) { color: blue; }
606
+ article .red { color: red; }
607
+ */
608
+ </pre>
609
+
610
+ <pre class="lang-html">
611
+ <article>
612
+ <div class="red blue"></div>
613
+ </article>
614
+
615
+ <!-- div text color is blue -->
616
+ </pre>
617
+
618
+ ''article :is(.blue, #gotcha)'' now has a specificity score of (1,1,1).
619
+ Nesting uses '':is()'' which assumes the specificity of it's highest selector.
620
+
621
+
622
+ To work around it, the following could be written instead:
595
623
596
624
<pre class="lang-css">
597
625
article {
598
- & .blue, & #gotcha { color: blue; }
599
- & .red { color: red; }
626
+ & .blue { color: blue; } /* (0,1,1) */
627
+ & .red { color: red; } /* (0,1,1) */
628
+ & #gotcha { color: blue; } /* (1,0,1) */
600
629
}
601
630
602
631
/* equivalent to
603
- article :is(.blue, #gotcha) {
604
- color: blue;
605
- }
632
+ article .blue { color: blue; }
606
633
article .red { color: red; }
634
+ article #gotcha { color: blue; }
607
635
*/
608
636
</pre>
609
637
@@ -612,14 +640,9 @@ Mixing Nesting Rules and Declarations {#mixing}
612
640
<div class="red blue"></div>
613
641
</article>
614
642
615
- /* div text color is blue */
643
+ <!-- div text color is red -->
616
644
</pre>
617
645
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
646
</div>
624
647
625
648
0 commit comments