Skip to content

Commit 4a65f42

Browse files
authored
Merge pull request #7019 from lilles/rune/cq-originating-20220207
[css-contain-3] Pseudo elements and shadow DOM #5984 #6711
2 parents 80f498d + 87e67ed commit 4a65f42

File tree

1 file changed

+79
-2
lines changed

1 file changed

+79
-2
lines changed

css-contain-3/Overview.bs

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ Container Queries</h2>
273273
A [=query container=] is established by specifying
274274
the possible query types using the 'container-type' property
275275
(or the 'container' [=shorthand=]).
276-
Style rules applying to its descendants can then be conditioned
277-
by querying against it,
276+
Style rules applying to its <a>shadow-including descendants</a> can then be
277+
conditioned by querying against it,
278278
using the ''@container'' [=conditional group rule=].
279279

280280
<div class=example>
@@ -303,6 +303,83 @@ Container Queries</h2>
303303
will each respond to their own container context.
304304
</div>
305305

306+
For selectors with pseudo elements, query containers can be established by
307+
the <a>shadow-including inclusive ancestors</a> of the <a>ultimate
308+
originating element</a>.
309+
310+
<div class=note>
311+
It follows that:
312+
313+
* Pseudo elements themselves can not be query containers
314+
* ''::before'', ''::after'', ''::marker'', and ''::backdrop'' query their
315+
originating elements
316+
* ''::first-letter'' and ''::first-line'' query their originating elements,
317+
even if the <a>fictional tag sequence</a> may push the
318+
<code>::first-line</code> past other elements for the purpose of
319+
inheritance and rendering
320+
* Multiple pseudo elements do not allow pseudo elements to be query
321+
containers for other pseudo elements. E.g., the host, but not the
322+
<code>::part()</code>, can be the query container for
323+
<code>::before</code> in <code>host::part()::before</code>. Similarly,
324+
<code>::before</code> can not be the query container for the
325+
<code>::marker</code> in <code>div::before::marker</code>
326+
* ''::slotted()'' selectors can query containers inside the shadow tree,
327+
including the slot itself
328+
* ''::part()'' selectors can query its originating host, but not internal
329+
query containers inside the shadow tree
330+
* ''::placeholder'' and ''::file-selector-button'' can query the input
331+
element, but do not expose any internal containers if the input element is
332+
implemented using a shadow tree
333+
</div>
334+
335+
<div class=example>
336+
A ::before selector querying the size of the originating element:
337+
338+
<pre class=lang-html>
339+
&lt;style>
340+
#container {
341+
width: 100px;
342+
container-type: inline-size;
343+
}
344+
@container size(inline-size < 150px) {
345+
#inner::before {
346+
content: "BEFORE";
347+
}
348+
}
349+
&lt;/style>
350+
&lt;div id=container>
351+
&lt;span id=inner>&lt;/span>
352+
&lt;/div>
353+
</pre>
354+
</div>
355+
356+
<div class=example>
357+
A ::slotted() selector for styling a shadow host child can query a
358+
container in the shadow tree:
359+
360+
<pre class=lang-html>
361+
&lt;div id=host style="width:200px">
362+
&lt;template shadowroot=open>
363+
&lt;style>
364+
#container {
365+
width: 100px;
366+
container-type: inline-size;
367+
}
368+
@container size(inline-size < 150px) {
369+
::slotted(span) {
370+
color: green;
371+
}
372+
}
373+
&lt;/style>
374+
&lt;div id=container>
375+
&lt;slot />
376+
&lt;/div>
377+
&lt;/template>
378+
&lt;span id=slotted>Green&lt;/span>
379+
&lt;/div>
380+
</pre>
381+
</div>
382+
306383
<h3 id="container-type">
307384
Creating Query Containers: the 'container-type' property</h3>
308385

0 commit comments

Comments
 (0)