Solice UI
Back to the curriculum

Chapter 3 · CSS & Layout

Selectors and cascade

Several CSS rules can target the same element. The cascade is the browser's predictable way of choosing the winning value, so you can resolve conflicts without reaching for stronger selectors every time.

Beginner · Lesson 1 of 6 in this chapter

Selectors choose elements

Type, class, attribute, and state selectors describe which elements a rule affects. Start with selectors that express a stable role; long chains tied to page structure are harder to understand and reuse.

The cascade compares competing rules

Origin, importance, cascade layer, specificity, and source order help determine the winner. Inheritance is separate: some values, such as text color, can flow from a parent when the child has no winning value of its own.

Styling a primary button

  1. A shared button class provides shape and spacing.
  2. A primary variant class supplies the accent colors.
  3. A hover rule changes only the interactive state instead of repeating the whole button style.
  • Use stable, readable selectors.
  • Source order matters only after stronger cascade factors tie.
  • Prefer a clear style system over repeated specificity battles.