×

css · level 3 · unit 2 · lesson 3

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Put rules in cascade layers, and the later layer wins.

Big stylesheets turn into specificity wars: someone adds an id to win, the next person adds two. A ends that. @layer base { … } puts rules into a named group, and the browser compares groups before it ever counts specificity.

When rules in two layers disagree, the one in the later layer wins, even if the earlier rule has an id and the later one is a single tag. Inside one layer, the usual rules apply: weight first, then order.

<p id="intro" class="lead">Welcome back, Sam.</p>
@layer base {
  #intro {
    color: crimson;
  }
}
@layer theme {
  p {
    color: #264653;
  }
}

Press show my page to see it here.

The plain p beats the id, because the theme layer comes after base.