@@ -522,48 +522,47 @@ Syntax {#syntax}
522
522
</div>
523
523
524
524
<div class=note>
525
- Some CSS-generating tools will concatenate selectors like strings,
526
- allowing authors to build up a single simple selector
525
+ Some CSS-generating tools that preprocess nesting
526
+ will concatenate selectors as strings,
527
+ allowing authors to build up a <em> single</em> [=simple selector=]
527
528
across nesting levels.
528
- This is sometimes used by selector-organization methods
529
+ This is sometimes used with hierarchical name patterns
529
530
like <a href="https://en.wikipedia.org/wiki/CSS#:~:text=bem%20(block%2C%20element%2C%20modifier)">BEM</a>
530
531
to reduce repetition across a file,
531
532
when the selectors themselves have significant repetition internally.
532
533
533
534
For example, if one component uses the class ''.foo'' ,
534
- and a nested component uses ''.foo__bar '' ,
535
+ and a nested component uses ''.fooBar '' ,
535
536
you could write this in <a href="https://sass-lang.com/">Sass</a> as:
536
537
537
538
<pre class="lang-css">
538
539
.foo {
539
- color: blue;
540
- &__bar { color: red; }
540
+ color: blue;
541
+ &Bar { color: red; }
541
542
}
542
543
/* In Sass, this is equivalent to
543
544
.foo { color: blue; }
544
- .foo__bar { color: red; }
545
+ .fooBar { color: red; }
545
546
*/
546
547
</pre>
547
548
548
- Unfortunately, this method is inconsistent with selector syntax in general,
549
- and at best requires heuristics tuned to particularly selector-writing practices
550
- to recognize when the author wants it,
551
- versus the author attempting to add a type selector in the nested rule.
552
- ''__bar'' , for example,
549
+ Unfortunately, this string-based interpretation is ambiguous with
550
+ the author attempting to add a type selector in the nested rule.
551
+ ''Bar'' , for example,
553
552
<em> is</em> a valid <a href="https://html.spec.whatwg.org/multipage/custom-elements.html">custom element name</a> in HTML.
554
553
555
- As such, CSS can 't do this;
556
- the nested selector components are interpreted on their own ,
557
- and not " concatenated" :
554
+ CSS doesn 't do this:
555
+ the nested selector components are interpreted atomically ,
556
+ and not string- concatenated:
558
557
559
558
<pre class="lang-css">
560
559
.foo {
561
- color: blue;
562
- &__bar { color: red; }
560
+ color: blue;
561
+ &Bar { color: red; }
563
562
}
564
563
/* In CSS, this is instead equivalent to
565
564
.foo { color: blue; }
566
- __bar .foo { color: red; }
565
+ Bar .foo { color: red; }
567
566
*/
568
567
</pre>
569
568
</div>
0 commit comments