Forming an Exclusive Club

If regular class styles are like clubs that any tag can join, then you can also define exclusive clubs that only tags of a particular type can join. For instance, you can create a class style that doesn't affect all paragraphs in a document but only those paragraphs that belong to the class. First-level headers, second-level headers, and all the rest can't belong to the class unless you add them to the style selector.

Such a style rule looks like this:

p.bolditalic {
  font-weight: bold;
  font-style: italic;
}

See Figure 46.3 for an example of this style in action.

Listing 46.2. View Source for Figure 46.3.
 <p class="bolditalic">Only paragraphs can join the p.bolditalic class.</p> <p>This paragraph opts not to join, ...

Get Web Design Garage now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.