Skip to content

Commit 028aed6

Browse files
committed
[selectors-4] Edit in the more complete rules for matching featureless elements, and the WG-approved rule for matching :has(). w3c#10179 w3c#10693
1 parent 73ee458 commit 028aed6

File tree

1 file changed

+69
-16
lines changed

1 file changed

+69
-16
lines changed

selectors-4/Overview.bs

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -656,22 +656,6 @@ Data Model</h3>
656656
<li>Attributes, which are name-value pairs.
657657
</ul>
658658

659-
While individual elements may lack any of the above features,
660-
some elements are <dfn export>featureless</dfn>.
661-
A <a>featureless</a> element does not match any selector at all,
662-
except those it is explicitly defined to match
663-
(and [=logical combination pseudo-classes=] representing those selectors).
664-
If a given selector <em>is</em> allowed to match a <a>featureless</a> element,
665-
it must do so while ignoring the default namespace. [[CSS3NAMESPACE]]
666-
667-
<div class='example'>
668-
For example, the <a>shadow host</a> in a <a>shadow tree</a> is <a>featureless</a>,
669-
and can't be matched by <em>any</em> <a>pseudo-class</a>
670-
except for '':host'' and '':host-context()''
671-
(or combinations including those,
672-
such as '':is(:host, :root)'').
673-
</div>
674-
675659
Many of the selectors depend on the semantics of the <dfn export>document language</dfn>
676660
(i.e. the language and semantics of the document tree)
677661
and/or the semantics of the <dfn>host language</dfn>
@@ -683,6 +667,75 @@ Data Model</h3>
683667
to define what a ''::first-line'' pseudo-element represents
684668
and what it can do.
685669

670+
<h4 id=featureless-elements>
671+
Featureless Elements</h4>
672+
673+
While individual elements may lack any of the above features,
674+
some elements are <dfn export>featureless</dfn>.
675+
A <a>featureless</a> element does not match <em>any selector at all</em>,
676+
except:
677+
678+
* [=simple selectors=] it is explicitly defined to match
679+
* [=compound selectors=],
680+
if all contained [=simple selectors=]
681+
are allowed to match it
682+
* [=complex selectors=],
683+
if the [=compound selector=] targeting the [=selector/subject=]
684+
is allowed to match it
685+
* [=selector lists=],
686+
if at least one selector in the list
687+
is allowed to match it
688+
* [=logical combination pseudo-classes=],
689+
if their argument selector is allowed to match it
690+
* the '':has()'' pseudo-class,
691+
if and only if the [=compound selector=] it's part of
692+
contains at least one <em>other</em> [=simple selector=]
693+
that's allowed to match it.
694+
695+
If a selector would otherwise match a [=featureless=] element,
696+
except for the existence of the default namespace [[CSS-NAMESPACES-3]]
697+
(because [=featureless=] elements do not have a namespace
698+
unless otherwise defined),
699+
the default namespace does not prevent the match.
700+
701+
<div class='example'>
702+
For example, the [=shadow host=] in a [=shadow tree=] is [=featureless=],
703+
and can't be matched by <em>any</em> [=pseudo-class=]
704+
except for '':host'' and '':host-context()''
705+
(or combinations including those,
706+
such as '':is(:host, :root)'').
707+
708+
Logical combinations like '':not(.foo:host)''
709+
will never match the host element
710+
(even if it doesn't have a "foo" class),
711+
because not all of the simple selectors in ''.foo:host''
712+
are allowed to match the [=shadow host=].
713+
714+
Similarly, '':not(:host > .foo)'' will never match the [=shadow host=],
715+
even tho the [=shadow host=] is indeed *not* a descendant of itself
716+
and doesn't have the "foo" class,
717+
because the subject of the complex selector argument (''.foo'')
718+
isn't allowed to match the [=shadow host=].
719+
</div>
720+
721+
<div class='example'>
722+
In general, you can't match a [=featureless=] element
723+
without explicitly using one of the [=simple selectors=]
724+
it's allowed to match,
725+
to avoid accidentally selecting one of these elements
726+
(which are otherwise <em>intentionally</em> easy to not think about).
727+
For example, ''*'' will never match a [=featureless=] element.
728+
729+
The rule for '':has()'', above, works similarly.
730+
Even if a [=shadow host=] contains a ''.foo'' descendant,
731+
'':has(.foo)'' will not match it,
732+
because <em>the rest</em> of the compound selector
733+
(empty)
734+
doesn't contain a simple selector that can match the host.
735+
You have to write '':host:has(.foo)'' in order to match the host element.
736+
</div>
737+
738+
686739
<h3 id="scoping">
687740
Scoped Selectors</h3>
688741

0 commit comments

Comments
 (0)