CHAPTER 2

image

Grouping

To keep style sheets short and easy to edit, similar rules can be grouped together. This grouping offers several ways to specify a set of related rules. For example, you can color the text red and the background black for two header elements in four different ways, as described in the following sections.

Ungrouped rules

Each rule can be written separately, which allows you to apply individual style rules to each selected element.

h1 { color: red; }h1 { background: black; }h2 { color: red; }h2 { background: black; }

Grouped selectors

The selectors can be grouped together by separating them with a comma. This grouping will make ...

Get CSS Quick Syntax Reference 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.