Skip to content

Commit e003e3b

Browse files
committed
[css-cascade-5] Define the ordering of conditional layers (#6407)
1 parent a310957 commit e003e3b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

css-cascade-5/Overview.bs

+43
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,49 @@ Layer Ordering</h4>
15071507
4. ''utilities''
15081508
</div>
15091509

1510+
Layers that are defined inside of a [=conditional group rule=]
1511+
do not contribute to the layer order unless the condition is true,
1512+
or the [=conditional group rule=] evaluates contextually
1513+
for different elements on the page.
1514+
1515+
Note: A feature like "container queries"
1516+
would need to evaluate contextually for individual elements.
1517+
Because of that, layers defined inside a container query
1518+
would be considered part of the global layer order
1519+
regardless of the condition.
1520+
1521+
<div class=example>
1522+
For example,
1523+
the following layer order
1524+
will depend on which media conditions match:
1525+
1526+
<pre class='lang-css'>
1527+
@media (min-width: 30em) {
1528+
@layer layout {
1529+
.title { font-size: x-large; }
1530+
}
1531+
}
1532+
1533+
@media (prefers-color-scheme: dark) {
1534+
@layer theme {
1535+
.title { color: white; }
1536+
}
1537+
}
1538+
1539+
@layer theme layout;
1540+
</pre>
1541+
1542+
If the first media-query matches based on viewport dimensions,
1543+
then the ''layout'' layer will come first in the layer order.
1544+
If the color-scheme preference query matches,
1545+
or if neither condition is true,
1546+
then ''theme'' will come first in the layer order.
1547+
1548+
Authors who want to avoid this behavior can establish
1549+
an explicit ordering of layers in advance,
1550+
and avoid defining new layers inside conditional rules.
1551+
</div>
1552+
15101553
Note: [=Cascade layers=] are scoped to their [=origin=] and [=context=],
15111554
so the ordering of layers in the light DOM has no impact
15121555
on the order of identically-named layers in the shadow DOM

0 commit comments

Comments
 (0)