How Grouping Works

Another key concept in CSS is grouping. Grouping allows the creation of more efficient style sheets, in that selectors can be grouped in order to have the same style properties applied to all the selectors within the group. Similarly, properties can be listed in groups and applied to individual or grouped selectors.

✓ You also already worked with one example of creating a group selector in Chapter 3, “Setting Your Page's Base Styles,” when you applied style properties to both the H1 and H2 elements—see “Using a Group Selector to Set the Other Heading Characteristics,” p. 52 (chapter 3).

In CSS, selectors can be grouped by including them as a comma-separated list. Here's an example of grouping the H1, H2, H3, and H4 element ...

Get Cascading Style Sheets (CSS) by Example 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.