liveBook · Manning

Compound selector

As explained in CSS in Depth, Second Edition

A compound selector is a selector formed by combining multiple simple selectors without a combinator so that one element must match all of them.

A compound selector combines simple selectors without a space or other combinator. Every part must match the same element, as in a.featured: an <a> element with the featured class. section 1.1.4

Featured navigation link

With .nav a and a.featured at equal specificity, source order decides which declaration wins. The compound selector can turn the featured navigation link orange while retaining the shared navigation styles. However, applying class="featured" to a link outside the navigation may produce only the orange background, not the other button styles. section 1.1.4

Listing 1.10 Possible fix number four
.nav a {
  color: white;
  background-color: #13a4a4;
  padding: 5px;
  border-radius: 2px;
  text-decoration: none;
}

a.featured {                #1
  background-color: orange;
}

Inspect the compact a.featured rule alongside the broader .nav a rule to see how shared and conditional styles combine. section 1.1.4

How CSS in Depth, Second Edition covers it

How deep it goes
Explains matching, equal specificity, source-order resolution, and reuse consequences, but stops short of broader selector syntax.
Examples
Uses featured navigation links, an outside-navigation featured link, and competing .nav a and a.featured rules.
What it assumes
Assumes familiarity with CSS selectors and declarations while explaining compound matching and source-order effects through a link example.
What you can do after
Apply it to target elements meeting multiple conditions and evaluate whether the resulting styles remain complete outside their original context.
How it connects
Connects compound selectors with simple selectors, specificity, the cascade, source order, and class selectors.

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.