Resolving conflicting CSS rules by specificity

CSS is a declarative styling language: a stylesheet declares rules, and the browser's cascade decides which rule wins when several set the same property. A web page has a nav element with id nav. Inside it is a link, an a element, that has two classes, item and active. All five rules below match that link and appear in this source order. There are no inline styles and no !important declarations.


CSS
/* rule 1 */ #nav a { color: blue; }
/* rule 2 */ nav .item.active { color: green; }
/* rule 3 */ a.item { color: red; }
/* rule 4 */ #nav .item { color: purple; }
/* rule 5 */ #nav .active { color: orange; }


Give each answer as a whole number or a single word: the number of class selectors in rule 2, how many of the five rules contain exactly one ID selector, the number of the rule whose colour is applied, and the colour the link is drawn in.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Declarative Languages Questions: