Skip to content

Commit 76eefbb

Browse files
committed
[selectors-4] Make specificity of :matches(), :has(), and :nth-child() not depend on matching. (Use most specific argument, like :not().) #1027 (comment)
1 parent 8723f91 commit 76eefbb

1 file changed

Lines changed: 37 additions & 33 deletions

File tree

selectors-4/Overview.bs

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,14 +1115,17 @@ The Matches-any Pseudo-class: '':matches()''</h3>
11151115
It represents an element that is represented by its argument.
11161116

11171117
Note: The specificity of the '':matches()'' pseudo-class
1118-
is replaced by the specificity of its argument.
1119-
Thus, a selector written with '':matches()'' has equivalent specificity
1118+
is replaced by the specificity of its most specific argument.
1119+
Thus, a selector written with '':matches()''
1120+
does not necessarily have equivalent specificity
11201121
to the equivalent selector written without '':matches()''
1121-
For example,
1122+
For example, if we have
11221123
'':matches(ul, ol, .list) > [hidden]'' and ''ul > [hidden], ol > [hidden], .list > [hidden]''
1123-
are equivalent in both their matching behavior and specificity.
1124+
a ''[hidden]]'' child of an <{ol}> matches the first selector
1125+
with a specificity of (0,2,0)
1126+
whereas it matches the second selector
1127+
with a specificity of (0,1,1).
11241128
See [[#specificity-rules]].
1125-
ISSUE: See also <a href="https://github.com/w3c/csswg-drafts/issues/1027">issue 1027</a>.
11261129

11271130
Pseudo-elements cannot be represented by the matches-any pseudo-class;
11281131
they are not valid within '':matches()''.
@@ -1133,8 +1136,6 @@ The Matches-any Pseudo-class: '':matches()''</h3>
11331136
unless that compound selector contains
11341137
an explicit <a>universal selector</a> or <a>type selector</a>.
11351138

1136-
Issue: Why this exception for the explicit universal selector?
1137-
11381139
<div class="example">
11391140
For example, the following selector matches any element that is being
11401141
hovered or focused, regardless of its namespace. In particular, it
@@ -2807,8 +2808,9 @@ Child-indexed Pseudo-classes</h3>
28072808
</div>
28082809

28092810
Note: The specificity of the '':nth-child()'' pseudo-class is
2810-
the specificity of a single pseudo-class plus
2811-
the specificity of its selector argument <var>S</var>, if any.
2811+
the specificity of a single pseudo-class plus,
2812+
if <var>S</var> is specified,
2813+
the specificity of the most specific <a>complex selector</a> in <var>S</var>.
28122814
See [[#specificity-rules]].
28132815
Thus ''<var>S</var>:nth-child(<var>An+B</var>)''
28142816
and '':nth-child(<var>An+B</var> of <var>S</var>)''
@@ -3310,25 +3312,16 @@ Calculating a selector's specificity</h2>
33103312
A few pseudo-classes provide “evaluation contexts” for other selectors,
33113313
and so have their specificity defined by their contents and how they match:
33123314

3313-
ISSUE: See also <a href="https://github.com/w3c/csswg-drafts/issues/1027">issue 1027</a>.
3314-
33153315
<ul>
33163316
<li>
3317-
The specificity of a '':matches()'' or '':has()'' pseudo-class is replaced by
3318-
the specificity applicable to its selector list argument.
3319-
(When '':matches()'' contains only compound selectors,
3320-
the full selector's specificity is thus equivalent to
3321-
expanding out all the combinations in full, without '':matches()'';
3322-
fully generalized, the specificity of '':matches()'' is
3323-
the specificity of the most specific selector within it that matches.
3324-
The behavior for comma-separated arguments to '':has()'' is analogous.)
3317+
The specificity of a '':matches'', '':not()'', or '':has()'' pseudo-class
3318+
is replaced by the specificity of
3319+
the most specific complex selector in its selector list argument.
33253320
<li>
33263321
Analogously, the specificity of an '':nth-child()'' or '':nth-last-child()'' selector
33273322
is the specificity of the pseudo class itself (counting as one pseudo-class selector)
3328-
plus the specificity of its selector list argument (if any).
3329-
<li>
3330-
The specificity of a '':not()'' pseudo-class is replaced by
3331-
the specificity of the most specific complex selector in its selector list argument.
3323+
plus the specificity of
3324+
the most specific complex selector in its selector list argument (if any).
33323325
<li>
33333326
The specificity of a '':where()'' pseudo-class is replaced by zero.
33343327
</ul>
@@ -3338,18 +3331,25 @@ Calculating a selector's specificity</h2>
33383331
<ul>
33393332
<li>
33403333
'':matches(em, #foo)'' has
3341-
a specificity of (0,0,1)--like a tag selector--when matched against <code>&lt;em></code>,
3342-
and a specificity of (1,0,0)--like an ID selector--when matched against <code>&lt;em id=foo></code>.
3334+
a specificity of (1,0,0)--
3335+
like an ID selector--
3336+
when matched against any of
3337+
<code>&lt;em></code>, <code>&lt;p id=foo></code>, or <code>&lt;em id=foo></code>.
33433338
<li>
33443339
''div:where(em, #foo#bar#baz)'' has
3345-
a specificity of (0,0,1): only the ''div'' contributes to selector specificity.
3340+
a specificity of (0,0,1):
3341+
only the ''div'' outside the '':where()''
3342+
contributes to selector specificity.
33463343
<li>
33473344
'':nth-child(even of li, .item)'' has
3348-
a specificity of (0,1,1)--like a tag selector plus a pseudo-class--when matched against <code>&lt;li></code>,
3349-
and a specificity of (0,2,0)--like a class selector plus a pseudo-class--when matched against <code>&lt;li class=item id=foo></code>.
3345+
a specificity of (0,2,0)--
3346+
like a class selector plus a pseudo-class--
3347+
when matched against any of
3348+
<code>&lt;li></code>, <code>&lt;ul class=item></code>, or <code>&lt;li class=item id=foo></code>.
33503349
<li>
33513350
'':not(em, #foo)'' has
3352-
a specificity of (1,0,0)--like an ID selector--whenever it matches any element.
3351+
a specificity of (1,0,0)--like an ID selector--
3352+
whenever it matches any element.
33533353
</ul>
33543354
</div>
33553355

@@ -3380,17 +3380,16 @@ Calculating a selector's specificity</h2>
33803380
#x34y /* a=1 b=0 c=0 */
33813381
#s12:not(FOO) /* a=1 b=0 c=1 */
33823382
.foo :matches(.bar, #baz)
3383-
/* Either a=1 b=1 c=0
3384-
or a=0 b=2 c=0, depending
3385-
on the element being matched. */
3383+
/* a=1 b=1 c=0 */
33863384
</pre>
33873385
</div>
33883386

33893387
Note: Repeated occurrences of the
33903388
same simple selector are allowed and do increase specificity.
33913389

33923390
Note: The specificity of the styles
3393-
specified in an HTML <code>style</code> attribute <a href="https://www.w3.org/TR/css-style-attr/#interpret">is described in CSS Style Attributes</a>. [[CSSSTYLEATTR]]
3391+
specified in an HTML <code>style</code> attribute
3392+
<a href="https://www.w3.org/TR/css-style-attr/#interpret">is described in CSS Style Attributes</a>. [[CSSSTYLEATTR]]
33943393

33953394
<h2 id="grammar" oldids="formal-syntax">
33963395
Grammar</h2>
@@ -3913,8 +3912,13 @@ Changes</h2>
39133912
Significant changes since the <a href="https://www.w3.org/TR/2018/WD-selectors-4-20180202/">2 February 2018 Working Draft</a>:
39143913

39153914
<ul>
3915+
<li>Named the zero-specificity selector to '':where()''.
3916+
(<a href="https://github.com/w3c/csswg-drafts/issues/2143">Issue 2143</a>)
39163917
<li>Removed '':blank'' and defined '':empty'' to ignored white-space&ndash;only nodes.
39173918
(<a href="https://github.com/w3c/csswg-drafts/issues/1967">Issue 1967</a>)
3919+
<li>Changed the specificity of '':matches()'', '':where()'', and '':nth-child()''
3920+
to not depend on which selector argument matched.
3921+
(<a href="https://github.com/w3c/csswg-drafts/issues/1027">Issue 1027</a>)
39183922
</ul>
39193923

39203924
Significant changes since the <a href="https://www.w3.org/TR/2013/WD-selectors4-20130502/">2 May 2013 Working Draft</a> include:

0 commit comments

Comments
 (0)