Skip to content

Commit 86271a8

Browse files
committed
[css-contain-3] Pseudo elements and shadow DOM w3c#5984 w3c#6711
Per resolution for issues w3c#5984 and w3c#6711: w3c#5984 (comment) w3c#6711 (comment)
1 parent f000b68 commit 86271a8

File tree

1 file changed

+75
-2
lines changed

1 file changed

+75
-2
lines changed

css-contain-3/Overview.bs

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

0 commit comments

Comments
 (0)