liveBook · Manning

Class selector

As explained in CSS in Depth, Second Edition

A CSS class selector matches elements whose class attribute contains a specified class name.

A class selector matches elements whose class attribute contains a specified class name, such as .featured. Its declaration can still lose when another matching selector has greater specificity. section 1.1.3

When a class rule does not win, consider the specificity hierarchy:

  • An ID selector outranks a class selector, while a class selector outranks a tag selector. section 1.1.3

How CSS in Depth, Second Edition covers it

How deep it goes
Explains selector specificity with contrasting listings and fixes, but stops short of broader stylesheet-origin rules.
Examples
Uses featured links, navigation selectors, specificity listings, and alternative fixes involving !important and targeted selectors.
What you can do after
Apply it via CSS by diagnosing why a class rule loses and choosing a more targeted selector when appropriate.
How it connects
Connects class selectors to CSS specificity, ID selectors, type selectors, and the cascade.

Also explained in

Compare how 2 books explain class selector →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of CSS in Depth, Second Edition. The section links point to the parts of the book it draws on.