Skip to content

Commit 663b4b5

Browse files
committed
[css-contain-3] Allow comma-separated conditions to match different
containers (w3c#7551)
1 parent ed383b5 commit 663b4b5

File tree

1 file changed

+51
-13
lines changed

1 file changed

+51
-13
lines changed

css-contain-3/Overview.bs

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ Container Queries: the ''@container'' rule</h3>
579579
The syntax of the ''@container'' rule is:
580580

581581
<pre class="prod def">
582-
@container <<container-condition>> {
582+
@container <<container-condition>># {
583583
<<block-contents>>
584584
}
585585
</pre>
@@ -612,9 +612,9 @@ Container Queries: the ''@container'' rule</h3>
612612
is selected from among the element’s ancestor [=query containers=]
613613
that are established as a valid [=query container=]
614614
for all the [=container features=]
615-
in the <<container-query>>. If the <<container-query>> contains unknown
616-
or unsupported [=container feature=]s, no [=query container=] will be
617-
selected.
615+
in the <<container-query>>. If the <<container-query>> contains
616+
unknown or unsupported [=container feature=]s,
617+
no [=query container=] will be selected for that <<container-condition>>.
618618
The optional <<container-name>>
619619
filters the set of [=query containers=] considered
620620
to just those with a matching [=query container name=].
@@ -623,12 +623,20 @@ Container Queries: the ''@container'' rule</h3>
623623
each [=container feature=] in the <<container-query>>
624624
is evaluated against that [=query container=].
625625
If no ancestor is an eligible [=query container=],
626-
then the [=container query=] is ''unknown'' for that element. As for media queries,
627-
<<general-enclosed>> evaluates to ''unknown''.
626+
then the [=container query=] is ''unknown'' for that element.
627+
As with media queries, <<general-enclosed>> evaluates to ''unknown''.
628+
629+
If a [=container query=] includes multiple <<container-condition>>s,
630+
each condition will select it's own [=query container=],
631+
and evaluate independently.
632+
A [=container query=] is ''true'' if <em>any</em> of its component
633+
<<container-condition>>s are ''true'',
634+
and ''false'' only if <em>all</em> of its component
635+
<<container-condition>>s are ''false''.
628636

629637
<div class=example>
630638
As with [=media queries=],
631-
we can string together multiple conditions in a single query list:
639+
we can string together multiple queries in a single condition:
632640

633641
<pre class=lang-css>
634642
@container card (inline-size > 30em) and style(--responsive: true) {
@@ -640,6 +648,21 @@ Container Queries: the ''@container'' rule</h3>
640648
if there is an ancestor container named "card"
641649
that meets both the '@container/inline-size'
642650
and [=container style query|style=] conditions.
651+
652+
We can also combine multiple conditions into a list,
653+
with each condition evaluating against a different container:
654+
655+
<pre class=lang-css>
656+
@container card (inline-size > 30em), style(--large: true) {
657+
/* styles */
658+
}
659+
</pre>
660+
661+
The styles above will be applied
662+
if there is an ancestor container named "card"
663+
that meets the '@container/inline-size' condition
664+
<em>or</em> the nearest style container
665+
meets the [=container style query|style=] condition.
643666
</div>
644667

645668
Style rules defined on an element inside multiple nested [=container queries=]
@@ -650,9 +673,22 @@ Container Queries: the ''@container'' rule</h3>
650673
into a single query.
651674

652675
<div class=example>
653-
While it is not possible to query multiple containers
654-
in a single [=container query=],
655-
that can be achieved by nesting multiple queries:
676+
Using a single comma-separated [=container query=],
677+
we can query multiple containers:
678+
679+
<pre class=lang-css>
680+
@container card (inline-size > 30em), style(--responsive: true) {
681+
/* styles */
682+
}
683+
</pre>
684+
685+
The styles above will apply for an element inside <em>either</em>
686+
a container named "card" that meets the '@container/inline-size' condition,
687+
<em>or</em> a container meeting the [=container style query|style=] condition.
688+
689+
In order to require that <em>all</em> conditions are met
690+
while querying multiple containers,
691+
we would need to nest multiple queries:
656692

657693
<pre class=lang-css>
658694
@container card (inline-size > 30em) {
@@ -663,10 +699,10 @@ Container Queries: the ''@container'' rule</h3>
663699
</pre>
664700

665701
The styles above will only be applied
666-
if there is an ancestor container named "card"
702+
if there is <em>both</em> an ancestor container named "card"
667703
that meets the '@container/inline-size' condition,
668-
as well as an ancestor container
669-
meeting [=container style query|style=] condition.
704+
<em>and</em> an ancestor container
705+
meeting the [=container style query|style=] condition.
670706
</div>
671707

672708
Global, name-defining [=at-rules=]
@@ -1162,6 +1198,8 @@ Changes since the 18 August 2022 Working Draft</h3>
11621198
(<a href="https://github.com/w3c/csswg-drafts/issues/8627">Issue 8627</a>)
11631199
* Allow ''var()'' references in [=container size queries=].
11641200
(<a href="https://github.com/w3c/csswg-drafts/issues/8088">Issue 8088</a>)
1201+
* Allow comma-separated <<container-condition>>s to match different containers.
1202+
(<a href="https://github.com/w3c/csswg-drafts/issues/7551">Issue 7551</a>)
11651203

11661204
<h3 id="changes-2021-12">
11671205
Changes since the 21 December 2021 First Public Working Draft</h3>

0 commit comments

Comments
 (0)