CodePark/ questions / Cascade, specificity & inheritance
START PRACTICINGPRACTICE
Frontend question · CSS & HTML › Cascade, specificity & inheritance

Which selector has the highest specificity?

#nav .item a

#nav .item a is right, with specificity (1,1,1): one id, one class and one type. Specificity is three counts, (ids, classes, types), compared from left to right.

div#nav a is the tempting wrong answer, at (1,0,2). It ties on ids. Then it loses, because the class column is compared before the type column. The other two have no id: ul.menu li.active a is (0,2,3) and .a .b .c .d is (0,4,0). Any id beats any number of classes.