XML technologies / CSS / Advanced websites with CSS / Behind the scenes / Selectors and the structure of CSS rules / Selector grouping

(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)

Selectors can also be grouped to create a single style rule for several elements in an HTML document. Simply separate the elements with commas.

Consider the following example:

h1, h2, h3 {
  font-family: Helvetica, Arial, sans-serif;
  color: green;
}

The elements in the selector need not belong to the same selector type or have the same level of detail. The following rule assigns all second-level headings (h2) and paragraphs the class spezial:

h2, p.spezial {
  font-size: 22px;
}

The space after the comma in the selector is optional and may be omitted.

  

 

 

 

back to top