Skip to content

Commit 017b4d7

Browse files
committed
[css-cascade-6] "Add @import scope()" syntax, allow reordering
Note that the Media Query part still needs to appear last in the grammar due to #10972.
1 parent 6b31ecb commit 017b4d7

File tree

1 file changed

+41
-8
lines changed

1 file changed

+41
-8
lines changed

css-cascade-6/Overview.bs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,23 @@ Importing Style Sheets: the ''@import'' rule</h2>
9292

9393
<pre class='prod'>
9494
@import [ <<url>> | <<string>> ]
95-
[ layer | layer(<<layer-name>>) ]?
96-
<<import-conditions>> ;
95+
[[ layer | layer(<<layer-name>>) ]
96+
|| [ scope( [ (<<scope-start>>) ]? [ to (<<scope-end>>) ]? ) | <<scope-start>> ]
97+
|| <<supports-import-condition>>]?
98+
<<media-import-condition>>?;
9799
98-
<dfn export>&lt;import-conditions></dfn> = [ supports( [ <<supports-condition>> | <<declaration>> ] ) ]?
99-
<<media-query-list>>?</pre>
100+
<dfn export>&lt;supports-import-condition></dfn> = [ supports( [ <<supports-condition>> | <<declaration>> ] ) ]
101+
<dfn export>&lt;media-import-condition></dfn> = <<media-query-list>></pre>
100102

101103
where:
102104

103105
* the <<url>> or <<string>>
104106
gives the URL of the style sheet to be imported.
105107

106-
* the optional ''layer'' keyword or ''layer()'' function
107-
assigns the contents of the style sheet
108+
and optionally:
109+
110+
* the ''layer'' keyword or ''layer()'' function,
111+
which assigns the contents of the style sheet
108112
into its own anonymous [=cascade layer=]
109113
or into the named [=cascade layer=].
110114

@@ -113,9 +117,24 @@ Importing Style Sheets: the ''@import'' rule</h2>
113117
but is subject to any [=import conditions=]
114118
(just as if declared by an ''@layer'' rule wrapped
115119
in the appropriate [=conditional group rules=]).
120+
* the ''scope()'' function,
121+
which [=scopes=] the [=style rules=] within the stylesheet,
122+
using the [=scoping roots=] and [=scoping limits=]
123+
as described by [[#scope-limits]].
124+
125+
Note: While the [=style rules=] within the imported stylesheet
126+
become [=scoped=],
127+
they do not become [=nested style rule|nested=].
128+
In particular,
129+
top-level selectors are not re-interpreted as [=relative selectors=],
130+
and the ''&'' pseudo-class maintains its non-nested behavior.
131+
132+
* the [=import conditions=],
133+
<<supports-import-condition>> and <<media-import-condition>>,
134+
which state the conditions under which the ''@import'' rule applies.
116135

117-
* the optional <<import-conditions>>
118-
states the [=import conditions=] under which it applies.
136+
Issue(10972): Accept <<media-import-condition>> at any point
137+
after the URL/string.
119138

120139
<div class="example">
121140
The following <a href="#conditional-import">conditional <css>@import</css> rule</a>
@@ -137,6 +156,15 @@ Importing Style Sheets: the ''@import'' rule</h2>
137156
</pre>
138157
</div>
139158

159+
<div class="example">
160+
The following imports a stylesheet, and scopes the style rules
161+
to elements matching <code>.card</code>.
162+
163+
<pre>
164+
@import url("card.css") scope(.card);
165+
</pre>
166+
</div>
167+
140168
If a <<string>> is provided,
141169
it must be interpreted as a <<url>> with the same value.
142170

@@ -963,6 +991,11 @@ Changes since the 21 March 2023 Working Draft</h3>
963991
Significant changes since the
964992
<a href="https://www.w3.org/TR/2023/WD-css-cascade-6-20230321/">21 March 2023 Working Draft</a> include:
965993

994+
* Added the <code>@import scope()</code> syntax,
995+
and the ability to specificy ''layer()'', ''scope()'', and ''supports()''
996+
in any order.
997+
(<a href="https://github.com/w3c/csswg-drafts/issues/7348">Issue 7348</a>)
998+
966999
* Allowed [=declarations=] directly within ''@scope''.
9671000
(<a href="https://github.com/w3c/csswg-drafts/issues/10389">Issue 10389</a>)
9681001

0 commit comments

Comments
 (0)