Skip to content

Commit 43fa98f

Browse files
committed
[css-nesting-1] adding more clarity to relative order examples
1 parent 2299fea commit 43fa98f

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

css-nesting-1/Overview.bs

+38-15
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,8 @@ Mixing Nesting Rules and Declarations {#mixing}
573573

574574
<pre class="lang-css">
575575
article {
576-
& .blue { color: blue; }
577-
& .red { color: red; }
576+
& .blue { color: blue; } /* (0,1,1) */
577+
& .red { color: red; } /* (0,1,1) */
578578
}
579579

580580
/* equivalent to
@@ -588,22 +588,50 @@ Mixing Nesting Rules and Declarations {#mixing}
588588
&#60;div class="red blue"&#62;&#60;/div&#62;
589589
&#60;/article&#62;
590590

591-
/* div text color is red */
591+
&#60;!-- div text color is red --&#62;
592592
</pre>
593593

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+
&#60;article&#62;
612+
&#60;div class="red blue"&#62;&#60;/div&#62;
613+
&#60;/article&#62;
614+
615+
&#60;!-- div text color is blue --&#62;
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:
595623

596624
<pre class="lang-css">
597625
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) */
600629
}
601630

602631
/* equivalent to
603-
article :is(.blue, #gotcha) {
604-
color: blue;
605-
}
632+
article .blue { color: blue; }
606633
article .red { color: red; }
634+
article #gotcha { color: blue; }
607635
*/
608636
</pre>
609637

@@ -612,14 +640,9 @@ Mixing Nesting Rules and Declarations {#mixing}
612640
&#60;div class="red blue"&#62;&#60;/div&#62;
613641
&#60;/article&#62;
614642

615-
/* div text color is blue */
643+
&#60;!-- div text color is red --&#62;
616644
</pre>
617645

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.
623646
</div>
624647

625648

0 commit comments

Comments
 (0)