selectors & specificity

[check: โ€ฆ]
๐Ÿ“– Guide (.md) for the concepts ยท ๐Ÿ“„ source code (.js) is the computable ground truth.

Three rules, one element โ€” specificity decides

Three rules all set color on the same link. They are ordered winner first, so the green win is specificity, not source order.

rendered color: โ€”

selector(a,b,c)color tried
#nav .item a(1,1,1)green
.item a (0,1,1)yellow
a (0,0,1)red
winner  highest (a,b,c), compared left-to-right → green

Compare the ID column first: 1 > 0, so #nav .item a wins outright โ€” the CLASS and TYPE columns are never even looked at.

Compute a selector's specificity

Same specificity() function as selectors_specificity.js. Type a selector:

(1,1,1)   decimal 111

Try: li ยท ul li ยท .item ยท #nav ยท a[href]:hover ยท ::before ยท * ยท .a.b.c