Selector Combinations

Detailed Strategies for Targeting HTML Elements

Selecting multiple elements #

To select multiple elements, separate the selectors by commas, like so:

/* Selecting multiple HTML element types */
h1, p {
  border: 1px solid black;
}

/* Selecting styles to be applied to several classes */
.ingredientsList, .instructionsList {
  font-size: 1.2em;
}

/* Using multiple kinds of selectors*/
h3, .red, #redElement{
  color: red;
}

Exercise #

Give a color property (with a value of orange) to all the header elements (elements with the h1 or h2 tags) on the page with a single CSS rule.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy