Skip to content

Commit 496c35c

Browse files
committed
[css-cascade-5] Tighten up cascade layers prose.
1 parent f897eba commit 496c35c

File tree

1 file changed

+65
-47
lines changed

1 file changed

+65
-47
lines changed

css-cascade-5/Overview.bs

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -869,17 +869,18 @@ Cascade Sorting Order</h3>
869869

870870
<dt id='cascade-layering'>Layers
871871
<dd>
872-
Declarations can be explicitly assigned to a [=cascade layer=].
873-
Explicit layers are listed in the document order where they are first introduced.
872+
Declarations within each [=origin=] and [=context=]
873+
can be explicitly assigned to a [=cascade layer=].
874874
For the purpose of this step,
875875
any declaration not assigned to an explicit layer is added to an implicit final layer.
876876

877+
Cascade layers (like declarations) are ordered by order of appearance.
877878
When comparing declarations that belong to different layers,
878879
then for [=normal=] rules the declaration whose [=cascade layer=] is last wins,
879880
and for [=important=] rules the declaration whose [=cascade layer=] is first wins.
880881

881882
Note: This follows the same logic used for layering [=normal=] and [=important=] [=origins=],
882-
so that the ''!important'' flag maintains the same semantic purpose in both settings.
883+
so that the ''!important'' flag maintains the same “override” purpose in both settings.
883884

884885
Issue(w3c/csswg-drafts#5003): Where do Layers fit in the cascade?
885886

@@ -1040,12 +1041,12 @@ Cascade Layers</h3>
10401041

10411042
In the same way that [=cascade origins=] provide a balance of power
10421043
between user and author styles,
1043-
<dfn export>Cascade Layers</dfn> provide an explicit way
1044-
to balance concerns within a single origin.
1044+
<dfn export>cascade layers</dfn> provide a structured way
1045+
to organize and balance concerns within a single origin.
10451046
Authors can create layers to represent element defaults,
10461047
third-party libraries, themes, components,
1047-
overrides, and other styling concerns --
1048-
and re-order the cascade of layers in a deterministic way,
1048+
overrides, and other styling concerns--
1049+
and are able to re-order the cascade of layers in an explicit way,
10491050
without altering selectors or specificity within each layer,
10501051
or relying on source-order to resolve conflicts across layers.
10511052

@@ -1076,10 +1077,10 @@ Cascade Layers</h3>
10761077
Issue(w3c/csswg-drafts#5793): Do we need a keyword similar to `revert`, but for cascade layers?
10771078

10781079
<h4 id="at-layer">
1079-
Layering Styles: the ''@layer'' rule</h4>
1080+
Declaring Cascade Layers: the ''@layer'' rule</h4>
10801081

10811082
The <dfn at-rule id="at-ruledef-layer">@layer</dfn> rule
1082-
describes an explicit [=cascade layer=],
1083+
defines an explicit [=cascade layer=],
10831084
with the option to assign style rules as either a block or an import.
10841085

10851086
The import syntax is:
@@ -1088,6 +1089,10 @@ Layering Styles: the ''@layer'' rule</h4>
10881089
@layer <<layer-ident>>? <<url>>;
10891090
</pre>
10901091

1092+
Such ''@layer'' import rules have the same restrictions and processing
1093+
as ''@import'' (see [[#at-import]]),
1094+
except that the imported rules are assigned to the indicated layer.
1095+
10911096
Issue(w3c/csswg-drafts#5681): Is ''@layer'' the proper way to handle layered url imports?
10921097

10931098
The block syntax is:
@@ -1098,30 +1103,46 @@ Layering Styles: the ''@layer'' rule</h4>
10981103
}
10991104
</pre>
11001105

1101-
In both cases the optional <dfn><<layer-ident>></dfn> is a
1102-
CSS <a href="https://www.w3.org/TR/CSS21/syndata.html#value-def-identifier">identifier</a>
1103-
that either matches an existing layer name, or defines a new named layer.
1104-
If no identifier is given, a new unnamed layer is created.
1105-
The '<<url>>' import or '<<stylesheet>>' block
1106-
provides arbitrary CSS rules that will be appended to the layer.
1106+
Such ''@layer'' block rules have the same restrictions and processing
1107+
as a [=conditional rule=] [[CSS-CONDITIONAL-3]]
1108+
with a true condition.
1109+
1110+
In both cases the optional <dfn for='@layer'><<layer-ident>></dfn>
1111+
is a [=CSS identifier=] (<<ident>>)
1112+
that represents its <dfn>layer name</dfn>.
1113+
If the [=layer name=] matches that of a [=cascade layer=]
1114+
already defined within this [=origin=] and [=context=]
1115+
(and same [=layer=] scope, see [[#nested-layers]]),
1116+
then its style rules are assigned to that same [=cascade layer=].
1117+
Otherwise, or if no <<layer-ident>> is provided,
1118+
a new [=cascade layer=] is created.
1119+
1120+
Note: Layer name matching does not cross the shadow DOM boundary,
1121+
so the ordering of layers in the light DOM has no impact
1122+
on the order of identically-named layers in the shadow DOM.
1123+
1124+
Issue(w3c/csswg-drafts#4984): How do Cascade Layers interact with Shadow DOM?
11071125

11081126
The ''@layer'' rule can also be used to define new layers
1109-
without attaching any style rules, by providing only an identifier:
1127+
without assigning any style rules, by providing only a [=layer name=]:
11101128

11111129
<pre class='prod'>
11121130
@layer <<layer-ident>>;
11131131
</pre>
11141132

1115-
Issue(w3c/csswg-drafts#4969): What are the proper "levels" for managing Cascade Layers?
1133+
Such empty ''@layer'' are allowed
1134+
anywhere either import ''@layer'' or block ''@layer'' rules are allowed.
11161135

1117-
<h5 id="layer-identifiers" class="no-toc">
1118-
Layer Identifiers</h5>
1119-
1120-
Layer identifiers are optional,
1121-
but provide a way to apply multiple style blocks
1122-
to a single layer.
1136+
Issue(w3c/csswg-drafts#4969): What are the proper "levels" for managing Cascade Layers?
11231137

11241138
<div class="example">
1139+
Layer identifiers are optional,
1140+
but provide a way to apply multiple style blocks
1141+
to a single layer.
1142+
In the following example,
1143+
the contents of <code>headings.css</code> and <code>links.css</code>
1144+
are cascaded within the same layer as the <code>audio[controls]</code> rule:
1145+
11251146
<pre class='lang-css'>
11261147
@layer default url(headings.css);
11271148
@layer default url(links.css);
@@ -1134,13 +1155,14 @@ Layer Identifiers</h5>
11341155
</pre>
11351156
</div>
11361157

1137-
The identifier-only syntax
1138-
also allows authors to establish a layer order in advance,
1139-
regardless of the order in which style rules are added to each layer.
1140-
11411158
<div class="example">
1142-
In this example, the imported ''theme.css'' style will override
1143-
any style rules added to the ''default'',
1159+
The identifier-only syntax
1160+
allows establishing a layer order in advance,
1161+
regardless of the order in which style rules are added to each layer.
1162+
1163+
In this example,
1164+
the imported <code>theme.css</code> style rules will override
1165+
any rules added in the later <css>default</css> block
11441166
since the order of layers has already been established.
11451167

11461168
<pre class='lang-css'>
@@ -1160,22 +1182,16 @@ Layer Identifiers</h5>
11601182
See also [[#at-layers]].
11611183
</div>
11621184

1163-
Layer identifiers do not cross the shadow DOM boundary,
1164-
so the ordering of layers in the light DOM has no impact
1165-
on the order of identically-named layers in the shadow DOM.
1166-
1167-
Issue(w3c/csswg-drafts#4984): How do Cascade Layers interact with Shadow DOM?
1168-
11691185
<h5 id="nested-layers" class="no-toc">
11701186
Nested Layers</h5>
11711187

1172-
When multiple layer rules are nested,
1173-
internal layer identifiers are scoped to their parent layer.
1188+
When ''@layer'' rules are nested,
1189+
[=layer names=] are scoped to their parent layer.
11741190

11751191
<div class="example">
11761192
In this example,
1177-
the nested "framework default" layer is distinct
1178-
from the top-level "default" layer:
1193+
the nested ''framework default'' layer is distinct
1194+
from the top-level ''default'' layer:
11791195

11801196
<pre class='lang-css'>
11811197
@layer default {
@@ -1209,7 +1225,7 @@ Nested Layers</h5>
12091225
</div>
12101226

12111227
It is not possible for nested layers
1212-
to reference a layer identifier in an outer layer-scope,
1228+
to reference a [=layer name=] in an outer layer’s scope,
12131229
but it is possible to reference nested layers
12141230
from an outer scope,
12151231
by combining identifiers with a full stop (. U+002E) character.
@@ -1238,12 +1254,10 @@ Nested Layers</h5>
12381254
<h5 id="unnamed-layers" class="no-toc">
12391255
Un-Named Layers</h5>
12401256

1241-
Layers without an identifier are also added to the layer order when invoked,
1242-
but only describe a single rule-block or file import
1243-
without any external hook for re-arranging or adding styles.
1244-
1245-
12461257
<div class="example">
1258+
A layer declared without a [=layer name=]
1259+
does not provide any external hook for re-arranging or adding styles.
1260+
12471261
In most use-cases this would only be syntax-sugar for brevity --
12481262
relying on well-organized source-order rather than any explicit names.
12491263
However, it could be used by teams as a way to "force" an organizing convention
@@ -1279,10 +1293,12 @@ Layer-Ordering Shorthand: the ''@layers'' rule</h3>
12791293
Its syntax is:
12801294

12811295
<pre class='prod'>
1282-
@layers <<custom-ident>> [, <<custom-ident>>]* ;
1296+
@layers <<layer-ident>> [, <<layer-ident>>]* ;
12831297
</pre>
12841298

1285-
This is provided as a shorthand for establishing the order of named layers:
1299+
This is provided as a shorthand for establishing the order of named layers,
1300+
and otherwise has the same effect as declaring each [=layer name=]
1301+
in order in its own empty ''@layer'' rule.
12861302

12871303
<div class="example">
12881304
The following examples have the same result.
@@ -1302,6 +1318,8 @@ Layer-Ordering Shorthand: the ''@layers'' rule</h3>
13021318
</pre>
13031319
</div>
13041320

1321+
''@layers'' rules are allowed anywhere an empty ''@layer'' rule is allowed.
1322+
13051323
<h3 id="preshint">
13061324
Precedence of Non-CSS Presentational Hints</h3>
13071325

0 commit comments

Comments
 (0)