Skip to content

QuizNot attempted

Specificity

Which selector wins for the same property (no !important)?
#nav .item a { color: red; } /* A */
.nav .item:hover a { color: blue; } /* B */
nav ul li a { color: green; } /* C */
a.link.active { color: purple; } /* D */
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • A
  • Specificity is compared column by column as (ids, classes/attributes/pseudo-classes, elements), and A is the only selector with an id: A = (1,1,1), so it beats any number of classes.
  • Not B (0,3,1): three class-level parts (.nav, .item, :hover) still lose to one id.
  • Not C (0,0,4): four element selectors never outrank even one class.
  • Not D (0,2,1): two classes on the a are still zero ids.
  • Source order only decides an exact tie
  • inline styles beat all selectors and !important beats both.