Skip to content

Commit 95e86ea

Browse files
committed
[selectors] Define specificity of :nth-child() etc. when containing a selector list; also redefine specificity of :matches() in terms of selector list specificity. Add examples for everything.
1 parent ac1dab2 commit 95e86ea

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

selectors/Overview.bs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,19 +3005,39 @@ Calculating a selector's specificity</h2>
30053005
this number is calculated for each selector in the list,
30063006
and the specificity of the entire selector is the largest of any individual selector in the list that matches the element.
30073007

3008-
In most cases, a selector has the same specificity for every element it applies to.
3009-
A few pseudo-classes, however, instead provide "evaluation contexts" for other selectors,
3008+
A few pseudo-classes provide "evaluation contexts" for other selectors,
30103009
and so have their specificity defined by their contents and how they match:
30113010

3012-
* The specificity of a '':matches()'' pseudo-class
3013-
is the specificity of the most specific complex selector that matched the given element.
3014-
(The full selector's specificity is equivalent to expanding out all the combinations in full, without '':matches()''.)
3015-
* The specificity of a '':not()'' pseudo-class
3016-
is the specificity of the most specific complex selector in its selector list.
3017-
Within a '':not()'', the '':matches()'' pseudo-class has the highest specificity of any of its arguments.
3011+
<ul>
3012+
<li>
3013+
The specificity of a '':matches()'' pseudo-class is replaced by
3014+
the specificity of its selector list argument.
3015+
(The full selector's specificity is equivalent to expanding out all the combinations in full, without '':matches()''.)
3016+
<li>
3017+
Similarly, the specificity of an '':nth-child()'', '':nth-last-child()'', '':nth-of-type()'', or '':nth-last-of-type()'' selector
3018+
is the specificity of the pseudo class itself (counting as one pseudo-class selector)
3019+
plus the specificity of its selector list argument (if any).
3020+
<li>
3021+
The specificity of a '':not()'' pseudo-class is replaced by
3022+
the specificity of the most specific complex selector in its selector list argument.
3023+
</ul>
30183024

3019-
In either case, the pseudo-class itself does not contribute any additional specificity.
3020-
For example, '':matches(em, strong)'' has a specificity of (0,0,1), like a tag selector.
3025+
<div class="example">
3026+
For example:
3027+
<ul>
3028+
<li>
3029+
'':matches(em, #foo)'' has
3030+
a specificity of (0,0,1)--like a tag selector--when matched against <code>&lt;em></code>,
3031+
and a specificity of (1,0,0)--like an ID selector--when matched against <code>&lt;em id=foo></code>.
3032+
<li>
3033+
'':nth-child(even of li, .item)'' has
3034+
a specificity of (0,1,1)--like a tag selector plus a pseudo-class--when matched against <code>&lt;li></code>,
3035+
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>.
3036+
<li>
3037+
'':not(em, #foo)'' has
3038+
a specificity of (1,0,0)--like an ID selector--whenever it matches any element.
3039+
</ul>
3040+
</div>
30213041

30223042
Specificities are compared by comparing the three components in order:
30233043
the specificity with a larger <var>A</var> value is more specific;

0 commit comments

Comments
 (0)