Title: CSS Scoping Module Level 1 Level: 1 Shortname: css-scoping Group: CSSWG Status: ED Work Status: Exploring TR: https://www.w3.org/TR/css-scoping-1/ ED: https://drafts.csswg.org/css-scoping/ Previous Version: https://www.w3.org/TR/2014/WD-css-scoping-1-20140403/ Editor: Tab Atkins Jr., Google, http://xanthir.com/contact/, w3cid 42199 Abstract: This specification defines scoping/encapsulation mechanisms for CSS, focusing on the Shadow DOM scoping mechanism. Ignored Terms: inherit, slot, custom elements, stylesheets Ignored Vars: root elements
spec:dom; type:dfn; text:host text:shadow root; for:/ text:root; for:tree text:find slotables text:find flattened slotables spec:html; type:element; text:style spec:selectors-4; type:dfn; text: static profile text: dynamic profile spec:css-pseudo-4; type:selector; text:::before text:::after spec:cascade-4; type:dfn; text: inherit
:host( <When evaluated in the context of a shadow tree, it matches the shadow tree's shadow host if the shadow host, in its normal context, matches the selector argument. In any other context, it matches nothing. The [=specificity=] of '':host'' is that of a pseudo-class. The [=specificity=] of '':host()'' is that of a pseudo-class, plus the [=specificity=] of its argument. Note: This is different from the specificity of similar pseudo-classes, like '':matches()'' or '':not()'', which only take the specificity of their argument. This is because '':host'' is affirmatively selecting an element all by itself, like a "normal" pseudo-class; it takes a selector argument for syntactic reasons (we can't say that '':host.foo'' matches but ''.foo'' doesn't), but is otherwise identical to just using '':host'' followed by a selector.> )
<x-foo class="foo"> <"shadow tree"> <div class="foo">...</div> </> </x-foo>For a stylesheet within the shadow tree: * '':host'' matches the
<x-foo> element.
* ''x-foo'' matches nothing.
* ''.foo'' matches only the <div> element.
* ''.foo:host'' matches nothing
* '':host(.foo)'' matches the <x-foo> element.
:host-context( <When evaluated in the context of a shadow tree, the '':host-context()'' pseudo-class matches the shadow host, if the shadow host or one of its shadow-including ancestors matches the provided <> )
::slotted( <The ''::slotted()'' pseudo-element represents the elements that are: * assigned, after flattening, to the slot that is ''::slotted''’s originating element * matched by its <> )
<x-foo> <div id="one" slot="foo" class="foo">...</div> <div id="two" slot="foo">...</div> <div id="three" class="foo"> <div id="four" slot="foo">...</div> </div> <"shadow tree"> <div id="five">...</div> <div id="six">...</div> <slot name="foo"></slot> </"shadow tree"> </x-foo>For a stylesheet within the shadow tree, a selector like ''::slotted(*)'' selects ''#one'' and ''#two'' only, as they're the elements assigned to the sole <{slot}> element. It will not select ''#three'' (no
slot attribute)
nor ''#four''
(only direct children of a shadow host can be assigned to a slot).
A selector like ''::slotted(.foo)'',
on the other hand,
will only select ''#one'',
as it matches ''.foo'',
but ''#two'' doesn't.
Note: Note that a selector like ''::slotted(*)''
is equivalent to ''*::slotted(*)'',
where the ''*'' selects many more elements than just the <{slot}> element.
However, since only the <{slot}> elements are slots,
they're the only elements with a ''::slotted()'' pseudo-element as well.