@@ -576,29 +576,37 @@ Syntax {#syntax}
576
576
██████ ███████ ██ ██ ████████
577
577
-->
578
578
579
- Nesting Nesting Other At-Rules {#conditionals}
580
- -----------------------------------------
579
+ Nesting Other At-Rules {#conditionals}
580
+ --------------------------------------
581
581
582
582
In addition to [=nested style rules=] ,
583
- this specification allows <dfn export>nested conditional group rules</dfn>
584
- inside of [=style rules=] .
583
+ this specification allows <dfn export>nested group rules</dfn>
584
+ inside of [=style rules=] :
585
+ any at-rule whose body contains [=style rules=]
586
+ can be nested inside of a [=style rule=] as well.
585
587
586
588
When nested in this way,
587
- the contents of a [=conditional group rule=] are parsed as <<style-block>>
589
+ the contents of a [=nested group rule=] are parsed as <<style-block>>
588
590
rather than <<stylesheet>> :
589
591
590
- * Properties can be directly used,
591
- applying to the same elements as the parent rule
592
- (when the [=conditional group rule=] matches)
593
592
* [=Style rules=] are [=nested style rules=] ,
594
593
with their [=nesting selector=] taking its definition
595
594
from the nearest ancestor [=style rule=] .
595
+ * Properties can be directly used,
596
+ acting as if they were nested in a <code> & {...}</code> block.
596
597
597
- Issue: Do @media/etc gain a <code> .style</code> attribute
598
- to expose their properties,
599
- or do we pretend properties are wrapped in a ''& {...}'' rule,
600
- so we can just reflect them in the <code> .cssRules</code> attribute?
601
- (<a href="https://github.com/w3c/csswg-drafts/issues/7850">Issue 7850</a> )
598
+ <div class=note>
599
+ Specifically, these rules are capable of being [=nested group rules=] :
600
+
601
+ * all the [=conditional group rules=] (''@media'' , ''@supports'' )
602
+ * ''@layer''
603
+ * ''@scope''
604
+ * ''@container''
605
+ </div>
606
+
607
+ The meanings and behavior of such [=nested group rules=]
608
+ is otherwise unchanged,
609
+ unless otherwise specified.
602
610
603
611
<div class="example">
604
612
For example, the following conditional nestings are valid:
@@ -705,6 +713,88 @@ Nesting Nesting Other At-Rules {#conditionals}
705
713
</pre>
706
714
</div>
707
715
716
+ All directly-nested properties are treated
717
+ as if they were collected together, in order,
718
+ and nested in a [=nested style rule=]
719
+ with the selector ''&'' ,
720
+ and placed before all other child rules.
721
+
722
+ <div class=example>
723
+
724
+ For example, the earlier example:
725
+
726
+ <pre highlight=css>
727
+ .foo {
728
+ display: grid;
729
+
730
+ @media (orientation: landscape) {
731
+ grid-auto-flow: column;
732
+ }
733
+ }
734
+ /* equivalent to
735
+ .foo {
736
+ display: grid;
737
+
738
+ @media (orientation: landscape) {
739
+ & {
740
+ grid-auto-flow: column;
741
+ }
742
+ }
743
+ }
744
+ */
745
+ </pre>
746
+
747
+ is in fact <em> exactly</em> equivalent,
748
+ producing the exact same CSSOM structure.
749
+ The {{CSSMediaRule}} object
750
+ will have a single {{CSSStyleRule}} object
751
+ in its <code highlight=js> .childRules</code> attribute,
752
+ containing the 'grid-auto-flow' property.
753
+ </div>
754
+
755
+ Issue: Need to modify the serialization rules,
756
+ as in <a href="https://github.com/w3c/csswg-drafts/issues/7850#issuecomment-1288883780">this comment</a> ,
757
+ to remove the wrapping rule
758
+ when the first child rule is <code> & {...}</code> .
759
+
760
+ ### Nested ''@scope'' Rules {#nesting-at-scope}
761
+
762
+ When the ''@scope'' rule is a [=nested group rule=] ,
763
+ an ''&'' in the <<scope-start>> selector
764
+ refers to the elements matched
765
+ by the nearest ancestor style rule.
766
+
767
+ For the purposes of the style rules in its body
768
+ and its own <<scope-end>> selector,
769
+ the ''@scope'' rule is treated as an ancestor style rule,
770
+ matching the elements matched by its <<scope-start>> selector.
771
+
772
+ <div class=example>
773
+ That is, the following code:
774
+
775
+ <pre highlight=css>
776
+ .parent {
777
+ color: blue;
778
+
779
+ @scope (& > .scope) to (& .limit) {
780
+ & .content {
781
+ color: red;
782
+ }
783
+ }
784
+ }
785
+ </pre>
786
+
787
+ is equivalent to:
788
+
789
+ <pre highlight=css>
790
+ .parent { color: blue; }
791
+ @scope (.parent > .scope) to (.parent > .scope .limit) {
792
+ .parent > .scope .content {
793
+ color: red;
794
+ }
795
+ }
796
+ </pre>
797
+ </div>
708
798
709
799
<!--
710
800
██ ██ ████ ██ ██ ████ ██ ██ ██████
0 commit comments