@@ -230,13 +230,12 @@ Layer Ordering</h4>
230
230
██████ ██████ ███████ ██ ████ ██ ██ ██████
231
231
-->
232
232
233
- <h3 id='scoped-styles'>
234
- Scoped Styles</h3>
233
+ <h3 id='scoped-styles' oldids="scope-atrule" >
234
+ Scoping Styles: the ''@scope'' rule </h3>
235
235
236
236
A <dfn>scope</dfn> is a subtree or fragment of a document,
237
237
which can be used by selectors for more targeted matching.
238
-
239
- A [=scope=] can be formed by determining:
238
+ A [=scope=] is formed by determining:
240
239
241
240
* The [=scoping root=] [=node=] ,
242
241
which acts as the upper bound of the scope,
@@ -245,17 +244,19 @@ Scoped Styles</h3>
245
244
which act as the lower bounds.
246
245
247
246
An element is <dfn>in scope</dfn> if:
248
-
249
247
* It is an [=inclusive descendant=] of the [=scoping root=] , and
250
248
* It is not an [=inclusive descendant=] of a [=scoping limit=] .
251
249
252
- [=Scopes=] are described in CSS using the ''@scope'' rule.
253
-
254
250
Note: In contrast to [[CSS-SCOPING-1#shadow-dom|Shadow Encapsulation]] ,
255
251
which describes a persistent one-to-one relationship in the DOM
256
252
between a [=shadow host=] and its nested [=shadow tree=] ,
257
253
multiple overlapping [=scopes=] can be defined in relation to the same elements.
258
254
255
+ Scoped styles are described in CSS using
256
+ the <dfn>@scope</dfn> [=block at-rule=] ,
257
+ which declares a [=scoping root=] and optional [=scoping limits=]
258
+ associated with a set of [=style rules=] .
259
+
259
260
<div class=example>
260
261
For example,
261
262
an author might have wide-reaching color-scheme scopes,
@@ -317,24 +318,22 @@ Scoped Styles</h3>
317
318
</pre>
318
319
</div>
319
320
320
- <!--
321
- ███████ ██████ ██████ ███████ ████████ ████████
322
- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
323
- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██
324
- ██ ███ ██ ██████ ██ ██ ██ ████████ ██████
325
- ██ █████ ██ ██ ██ ██ ██ ██
326
- ██ ██ ██ ██ ██ ██ ██ ██ ██
327
- ███████ ██████ ██████ ███████ ██ ████████
328
- -->
321
+ <h4 id="scope-effects">
322
+ Effects of ''@scope''</h4>
329
323
330
- <h4 id='scope-atrule'>
331
- Scoping Styles: the ''@scope'' rule</h4>
332
324
333
- The <dfn>@scope</dfn> [=block at-rule=]
334
- allows authors to scope style rules in CSS,
335
- with the application of [=weak scoping proximity=]
336
- between the [=scoping root=] and the [=subject=] of each style rule.
337
- <!-- This causes declarations [insert appropriate sentence from issue below] . -->
325
+ The ''@scope'' [=at-rule=] has three primary effects
326
+ on the [=style rules=] it contains:
327
+
328
+ * The [=style rules=] in an ''@scope'' <<stylesheet>>
329
+ are [=scoped style rules=] .
330
+
331
+ * The [=cascade=] prioritizes declarations
332
+ with a [=scope proximity|more proximate=] [=scoping root=] ,
333
+ regardless of specificity or source order
334
+ by applying [=weak scoping proximity=]
335
+ between the [=scoping root=] and the [=subject=] of each [=scoped style rule=] .
336
+ <!-- This causes declarations [insert appropriate sentence from issue below] . -->
338
337
339
338
Issue(6790): Should ''@scope'' use strong or weak scoping proximity?
340
339
[=Strong scoping proximity=] causes declarations to be weighted more strongly
@@ -346,6 +345,13 @@ Scoping Styles: the ''@scope'' rule</h4>
346
345
The Working Group currently leans towards weak proximity,
347
346
and recommends that as a starting point for prototypes.
348
347
348
+ Note: Unlike <a href="https://www.w3.org/TR/css-nesting/">Nesting</a> ,
349
+ selectors within an ''@scope'' rule
350
+ do not acquire the specificity of any parent selector(s) in the ''@scope'' prelude.
351
+
352
+ <h4 id="scope-syntax">
353
+ Syntax of ''@scope''</h4>
354
+
349
355
The syntax of the ''@scope'' rule is:
350
356
351
357
<pre class="prod def">
@@ -356,51 +362,44 @@ Scoping Styles: the ''@scope'' rule</h4>
356
362
357
363
where:
358
364
359
- <pre class="prod def">
360
- <dfn><<scope-start>></dfn> = <<forgiving-selector-list>>
361
- <dfn><<scope-end>></dfn> = <<forgiving-selector-list>>
362
- </pre>
363
-
364
- A ''@scope'' rule which specifies a <<scope-start>>
365
- produces a number of <dfn>explicit scopes</dfn> as follows:
366
-
367
- * For each element matched by <<scope-start>> ,
368
- create a [=scope=] using that element as the [=scoping root=] .
369
- * For each [=scope=] created by the above:
370
- * Collect all elements that are [=in scope=]
371
- and that match <<scope-end>> ,
372
- using the [=scoping root=] as the '':scope'' element, then
373
- * Set those elements as the [=scoping limits=] .
365
+ * <dfn><<scope-start>></dfn> is a <<forgiving-selector-list>> [=selector=]
366
+ used to identify the [=scoping root=] (s).
367
+ * <dfn><<scope-end>></dfn> is a <<forgiving-selector-list>> [=selector=]
368
+ used to identify any [=scoping limits=] .
369
+ * the <<stylesheet>> represents the [=scoped style rules=] .
374
370
375
371
[=Pseudo-elements=] cannot be [=scoping roots=] or [=scoping limits=] ;
376
372
they are invalid both within <<scope-start>> and <<scope-end>> .
377
373
378
- A ''@scope'' rule which does not specify a <<scope-start> >
379
- produces a single <dfn>implicit scope</dfn> as follows:
374
+ <h4 id="scoped-rules" >
375
+ Scoped Style Rules</h4>
380
376
381
- * The [=scoping root=] is the [=parent element=] of the [=owner node=]
382
- of the stylesheet where the ''@scope'' rule is defined.
383
- If no such element exist,
384
- then the [=scoping root=] is the [=root=] of the containing [=node tree=] .
385
- * Collect all elements that are [=in scope=]
386
- and that match <<scope-end>> ,
387
- using the [=scoping root=] as the '':scope'' element, then
388
- * Set those elements as the [=scoping limits=] .
377
+ <dfn>Scoped style rules</dfn> differ from non-scoped rules
378
+ in the following ways:
389
379
390
- The ''@scope'' [=at-rule=] has three primary effects
391
- on the [=style rules=] in its <<stylesheet>> :
380
+ * Their selectors can only match elements that are [=in scope=] .
381
+ (This only applies to the [=subject=] ;
382
+ the rest of the selector can match unrestricted.)
392
383
393
- * Selectors can only match elements that are [=in scope=] .
394
- This only applies to the [=subject=] ;
395
- the rest of the selector can match unrestricted.
384
+ <h4 id="scope-limits">
385
+ Identifying Scoping Roots and Limits</h4>
396
386
397
- * The [=cascade=] prioritizes declarations
398
- with a [=scope proximity|more proximate=] [=scoping root=] ,
399
- regardless of specificity or source order.
387
+ A ''@scope'' rule produces one or more [=scopes=] as follows:
388
+
389
+ : Finding the [=scoping root=] (s)
390
+ :: For each element matched by <<scope-start>> ,
391
+ create a [=scope=] using that element as the [=scoping root=] .
392
+ If no <<scope-start>> is specified,
393
+ the [=scoping root=] is the [=parent element=] of the [=owner node=]
394
+ of the stylesheet where the ''@scope'' rule is defined.
395
+ (If no such element exists,
396
+ then the [=scoping root=] is the [=root=] of the containing [=node tree=] .)
400
397
401
- Note: Unlike <a href="https://www.w3.org/TR/css-nesting/">Nesting</a> ,
402
- selectors within an ''@scope'' rule
403
- do not acquire the specificity of any parent selector(s) in the ''@scope'' prelude.
398
+ : Finding any [=scoping limits=]
399
+ :: For each [=scope=] created by a [=scoping root=] ,
400
+ its [=scoping limits=] are set to all elements
401
+ that are [=in scope=] and that match <<scope-end>> ,
402
+ using the [=scoping root=] as the '':scope'' element.
404
403
405
404
<div class=example>
406
405
The following selectors have the same specificity (0,0,1):
@@ -503,14 +502,17 @@ do not acquire the specificity of any parent selector(s) in the ''@scope'' prelu
503
502
</pre>
504
503
</div>
505
504
505
+ <h4 id="scope-scope">
506
+ Scope Nesting</h4>
507
+
506
508
''@scope'' rules can be nested.
507
509
In this case, just as with the nested style rules,
508
510
the selectors of the inner ''@scope''
509
511
(including those defining its [=scope=] )
510
512
are [=scoped selectors|scoped by=]
511
513
the selectors of the outer one.
512
514
513
- Global, name-defining [=at-rules=]
515
+ Global name-defining [=at-rules=]
514
516
such as ''@keyframes'' or ''@font-face'' or ''@layer''
515
517
that are defined inside ''@scope'' are valid,
516
518
but are not scoped or otherwise affected
@@ -643,7 +645,7 @@ Changes since the 21 December 2021 First Public Working Draft</h3>
643
645
644
646
* Added the {{CSSScopeRule}} interface.
645
647
646
- * Added [= implicit scopes=] .
648
+ * Added implicit scopes by making ''<<scope-start>>'' optional .
647
649
(<a href="https://github.com/w3c/csswg-drafts/issues/6606">Issue 6606</a> )
648
650
649
651
* Disallowed [=pseudo-elements=] in the ''@scope'' prelude.
0 commit comments