Chaining Selectors
Sometimes we need to select an element using multiple selectors to increase specificity.
We can achieve this by writing selectors one after another. For example:
h2.subheading {
background-color: red;
}
This code selects only the h2
elements with the class subheading
and sets their background color to red (background-color: red
).
It's important to note that chaining increases specificity. Therefore, the selector h2.subheading
would override the value of the .subheading
property on the h2
element in the case where both selectors modify the same property.
Instructions
Create a rule for div
elements with the class group
that sets the background color to gray.
Start programming for free
10/12