@@ -636,7 +636,7 @@ Nesting Other At-Rules {#conditionals}
636
636
with their [=nesting selector=] taking its definition
637
637
from the nearest ancestor [=style rule=] .
638
638
* Properties can be directly used,
639
- acting as if they were nested in an ''@nest'' rule.
639
+ acting as if they were nested in a [=nested declarations rule=] .
640
640
641
641
<div class=note>
642
642
Specifically, these rules are capable of being [=nested group rules=] :
@@ -667,11 +667,10 @@ Nesting Other At-Rules {#conditionals}
667
667
/* equivalent to: */
668
668
.foo {
669
669
display: grid;
670
-
671
- @media (orientation: landscape) {
672
- @nest {
673
- grid-auto-flow: column;
674
- }
670
+ }
671
+ @media (orientation: landscape) {
672
+ .foo {
673
+ grid-auto-flow: column
675
674
}
676
675
}
677
676
@@ -754,46 +753,9 @@ Nesting Other At-Rules {#conditionals}
754
753
</div>
755
754
756
755
Runs of consecutive directly-nested properties
757
- are automatically wrapped in ''@nest'' rules.
756
+ are automatically wrapped in [=nested declarations rules=] .
758
757
(This is observable in the CSSOM.)
759
758
760
- <div class=example>
761
-
762
- For example, the earlier example:
763
-
764
- <pre highlight=css>
765
- .foo {
766
- display: grid;
767
-
768
- @media (orientation: landscape) {
769
- grid-auto-flow: column;
770
- }
771
- }
772
- /* equivalent to */
773
- .foo {
774
- display: grid;
775
-
776
- @media (orientation: landscape) {
777
- @nest {
778
- grid-auto-flow: column;
779
- }
780
- }
781
- }
782
- </pre>
783
-
784
- is in fact <em> exactly</em> equivalent,
785
- producing the exact same CSSOM structure.
786
- The {{CSSMediaRule}} object
787
- will have a single {{CSSNestRule}} object
788
- in its <code highlight=js> .childRules</code> attribute,
789
- containing the 'grid-auto-flow' property.
790
- </div>
791
-
792
- Note: This does mean that the serialization of such rules will differ
793
- from how they were originally written,
794
- with <em> no</em> directly-nested properties in the serialization.
795
-
796
-
797
759
<h4 id=nesting-at-scope>
798
760
Nested ''@scope'' Rules</h4>
799
761
@@ -852,7 +814,7 @@ Mixing Nesting Rules and Declarations {#mixing}
852
814
and [=nested style rules=] or [=nested group rules=] ,
853
815
all three can be arbitrarily mixed.
854
816
Declarations coming after or between rules
855
- are implicitly wrapped in ''@nest'' rules,
817
+ are implicitly wrapped in [=nested declarations rules=] ,
856
818
to preserve their order relative to the other rules.
857
819
858
820
<div class=example>
@@ -867,18 +829,14 @@ Mixing Nesting Rules and Declarations {#mixing}
867
829
}
868
830
869
831
/* equivalent to */
870
- article {
871
- color: green;
872
- & { color: blue; }
873
- @nest { color: red; }
874
- }
832
+ article { color: green; }
833
+ :is(article) { color: blue; }
834
+ article { color: red; }
875
835
876
836
/* NOT equivalent to */
877
- article {
878
- color: green;
879
- color: red;
880
- & { color: blue; }
881
- }
837
+ article { color: green; }
838
+ article { color: red; }
839
+ :is(article) { color: blue; }
882
840
</pre>
883
841
</div>
884
842
@@ -917,7 +875,7 @@ Mixing Nesting Rules and Declarations {#mixing}
917
875
918
876
Note: While one <em> can</em> freely intermix declarations and nested rules,
919
877
it's harder to read and somewhat confusing to do so,
920
- since the later properties are automatically wrapped in an ''@nest'' rule
878
+ since the later properties are automatically wrapped in a [=nested declarations rule=]
921
879
that doesn't appear in the source text.
922
880
For readability's sake,
923
881
it's recommended that authors put all their properties first in a style rule,
@@ -1139,19 +1097,19 @@ Nesting Selector: the ''&'' selector {#nest-selector}
1139
1097
(that is, ''&div'' is illegal, and must be written ''div&'' instead).
1140
1098
1141
1099
1142
- <!-- Big Text: @nest
1100
+ <!-- Big Text: Nested Decl
1143
1101
1144
- █ ███▌ █ █ ▌ █████▌ ███▌ █████▌
1145
- █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
1146
- █▌▐█ █▌ █ █▌ █▌ █▌ █▌ █▌
1147
- █▌▐█ █▌ █▌▐█ █▌ █ ███ ███▌ █▌
1148
- █▌ ██▌ █▌ █ █▌ █▌ █▌ █▌
1149
- █▌ █▌ █▌ █▌ █▌ █▌ █▌
1150
- ████▌ █▌ ▐▌ █████▌ ███▌ █▌
1102
+ █ █▌ █████ ▌ ███▌ █████ ▌ █████▌ ████▌ ████ ▌ █████▌ ███▌ █▌
1103
+ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
1104
+ ██▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
1105
+ █▌▐█ █▌ ████ ███▌ █▌ ████ █▌ █▌ █▌ █▌ ████ █▌ █▌
1106
+ █▌ ██▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
1107
+ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
1108
+ █▌ ▐▌ █████ ▌ ███ ▌ █▌ █████▌ ████▌ ████ ▌ █████▌ ███▌ █████
1151
1109
-->
1152
1110
1153
- <h2 id=nest -rule>
1154
- The ''@nest'' Rule</h2>
1111
+ <h2 id=nested-declarations -rule>
1112
+ The Nested Declarations Rule</h2>
1155
1113
1156
1114
For somewhat-technical reasons,
1157
1115
it's important to be able to distinguish properties
@@ -1205,34 +1163,21 @@ The ''@nest'' Rule</h2>
1205
1163
These run into the same problems as above.
1206
1164
1207
1165
To address all of these issue,
1208
- the <dfn at-rule>@nest</dfn> rule is defined:
1209
-
1210
- <pre class=prod>
1211
- <@nest> = @nest { <<block-contents>> }
1212
- </pre>
1166
+ we instead wrap runs of consecutive directly-nested properties
1167
+ in a <dfn export>nested declarations rule</dfn> .
1213
1168
1214
1169
Unless otherwise specified,
1215
- an ''@nest'' rule is a [=nested style rule=] ,
1170
+ a [=nested declarations rule=] is a [=nested style rule=] ,
1216
1171
and acts identically to any other style rule.
1217
1172
It matches the exact same elements and pseudo-elements
1218
1173
as its parent style rule,
1219
1174
with the same specificity behavior.
1220
1175
<span class=note> (This is <em> similar to</em> being a style rule with an ''&'' selector,
1221
1176
but slightly more powerful,
1222
1177
as explained above.)</span>
1223
- If it does not have a parent style rule,
1224
- it matches elements as if it were a [=style rule=] with a '':scope'' selector.
1225
-
1226
- Note: While it is <em> possible</em> to manually specify an ''@nest'' rule in a stylesheet,
1227
- there's never any reason to.
1228
- The parser automatically produces them when needed.
1229
-
1230
- Issue: It's possible that we might make changes to further hide the existence of ''@nest'' ,
1231
- such as serializing as just its declarations when possible.
1232
- See <a href="https://github.com/w3c/csswg-drafts/issues/8738#issuecomment-2061777236">Issue 8738</a> .
1233
1178
1234
1179
<details class=note>
1235
- <summary> Why does the ''@nest'' rule exist?</summary>
1180
+ <summary> Why does the [=nested declarations rule=] exist?</summary>
1236
1181
1237
1182
Originally, this specification grouped all declarations in style rules together,
1238
1183
"moving" them from their original location
@@ -1241,15 +1186,15 @@ The ''@nest'' Rule</h2>
1241
1186
in plain style rules,
1242
1187
using the ''&'' selector.
1243
1188
1244
- There are two major reasons we switched to instead use the ''@nest'' rule.
1189
+ There are two major reasons we switched to instead use the [=nested declarations rule=] .
1245
1190
1246
1191
First, using an ''& {...}'' rule to implicitly wrap declarations in a [=nested group rule=]
1247
1192
also changed the behavior.
1248
1193
As shown in the example following this note,
1249
1194
it breaks cases where the parent style rule contains pseudo-elements,
1250
1195
and even when that's not the case,
1251
1196
it potentially changes the specificity behavior of the nested declarations.
1252
- Switching to ''@nest'' avoids these problems,
1197
+ Switching to the [=nested declarations rule=] avoids these problems,
1253
1198
making the behavior of nested ''@media'' /etc
1254
1199
identical to the behavior of *non*-nested ''@media'' /etc.
1255
1200
@@ -1262,7 +1207,7 @@ The ''@nest'' Rule</h2>
1262
1207
and in order to actually make that representable in the CSSOM,
1263
1208
that means they have to be wrapped in some kind of rule.
1264
1209
The same issues as the previous paragraph apply if we just use a normal ''& {...}'' rule,
1265
- so ''@nest'' lets us do so without side effects.
1210
+ so the [=nested declarations rule=] lets us do so without side effects.
1266
1211
</details>
1267
1212
1268
1213
<div class=example>
@@ -1295,14 +1240,14 @@ The ''@nest'' Rule</h2>
1295
1240
}
1296
1241
```
1297
1242
1298
- Then the ''color: white'' is implicitly wrapped in an ''@nest'' ,
1243
+ Then the ''color: white'' is implicitly wrapped in a [=nested declarations rule=] ,
1299
1244
which is guaranteed to match <em> exactly</em> the same as its parent style rule,
1300
1245
so the element <em> and</em> its pseudo-elements
1301
1246
would all have white text in a darkmode page.
1302
1247
</div>
1303
1248
1304
1249
<div class=example>
1305
- Declarations interleaved with rules get implicitly wrapped in an ''@nest'' ,
1250
+ Declarations interleaved with rules get implicitly wrapped in a [=nested declarations rule=] ,
1306
1251
which makes them part of a separate style rule.
1307
1252
For example, given this CSS:
1308
1253
@@ -1320,7 +1265,7 @@ The ''@nest'' Rule</h2>
1320
1265
the ''color: black'' one.
1321
1266
1322
1267
The ''background: silver'' declaration
1323
- will instead be found in the implicitly-created ''@nest'' child rule,
1268
+ will instead be found in the implicitly-created [=nested declarations rule|nested declarations child rule=] ,
1324
1269
at <code highlight=js> fooRule.cssRules[1] .style</code> .
1325
1270
</div>
1326
1271
@@ -1354,20 +1299,20 @@ with the implied [=nesting selector=] inserted.
1354
1299
will serialize as ''& > .foo'' .
1355
1300
</div>
1356
1301
1357
- The {{CSSNestRule }} Interface {#the-cssnestrule}
1302
+ The {{CSSNestedDeclarations }} Interface {#the-cssnestrule}
1358
1303
-----------------------------
1359
1304
1360
- The {{CSSNestRule }} interface represents an ''@nest'' rule.
1305
+ The {{CSSNestedDeclarations }} interface represents a [=nested declarations rule=] .
1361
1306
1362
1307
<xmp class=idl>
1363
1308
[Exposed=Window]
1364
- interface CSSNestRule : CSSGroupingRule {
1309
+ interface CSSNestedDeclarations : CSSRule {
1365
1310
[SameObject, PutForwards=cssText] readonly attribute CSSStyleProperties style;
1366
1311
};
1367
1312
</xmp>
1368
1313
1369
1314
<div algorithm>
1370
- The <dfn attribute for=CSSNestRule >style</dfn> attribute
1315
+ The <dfn attribute for=CSSNestedDeclarations >style</dfn> attribute
1371
1316
must return a {{CSSStyleProperties}} object for the rule,
1372
1317
with the following properties:
1373
1318
@@ -1383,35 +1328,13 @@ interface CSSNestRule : CSSGroupingRule {
1383
1328
:: Null
1384
1329
</div>
1385
1330
1386
- <div class=example>
1387
- Note that interleaved declarations,
1388
- or all declarations in [=nested group rules=] ,
1389
- will be implicitly wrapped in ''@nest'' rules,
1390
- which will affect the serialization.
1391
- A [=nested group rule=] like:
1392
-
1393
- <pre class=lang-css>
1394
- .foo {
1395
- @media (prefers-color-scheme: dark) {
1396
- color: white;
1397
- background: black;
1398
- }
1399
- }
1400
- </pre>
1331
+ The {{CSSNestedDeclarations}} rule [=serialize a CSS rule|serializes=]
1332
+ as if its [=CSS declaration block|declaration block=]
1333
+ had been [=serialize a CSS declaration block|serialized=] directly.
1401
1334
1402
- will serialize as:
1403
-
1404
- <pre class=lang-css>
1405
- .foo {
1406
- @media (prefers-color-scheme: dark) {
1407
- @nest {
1408
- color: white;
1409
- background: black;
1410
- }
1411
- }
1412
- }
1413
- </pre>
1414
- </div>
1335
+ Note: This means that multiple adjacent [=nested declarations rules=]
1336
+ (which is possible to create with e.g. {{CSSGroupingRule/insertRule}} )
1337
+ will collapse into a single rule when serialized and parsed again.
1415
1338
1416
1339
1417
1340
<!-- Big Text: changes -->
@@ -1439,6 +1362,9 @@ Significant changes since the
1439
1362
(<a href="https://github.com/w3c/csswg-drafts/issues/9069">Issue 9069</a> )
1440
1363
1441
1364
* Declarations intermixed with rules (or all declarations in nested group rules)
1442
- are now automatically wrapped in ''@nest'' rules.
1443
- (Also the ''@nest'' rule was added.)
1444
- (<a href="https://github.com/w3c/csswg-drafts/issues/8738">Issue 8738</a> )
1365
+ are now automatically wrapped in <code> @nest</code> rules.
1366
+ (Also the <code> @nest</code> rule was added.)
1367
+ (<a href="https://github.com/w3c/csswg-drafts/issues/8738">Issue 8738</a> )
1368
+
1369
+ * Replaced <code> @nest</code> with [=nested declarations rules=] .
1370
+ (<a href="https://github.com/w3c/csswg-drafts/issues/10234">Issue 10234</a> )
0 commit comments