In the world of CSS, there is no room for the word OR
. Instead, we have AND
, and to achieve a similar effect, we use the comma (,
) to separate multiple selectors.
So, when you need to apply the same styles to different selectors, you can list them out with commas like this:
.parentA .child,
.parentB .child {
/* rules here */
}
Each selector will then be targeted individually. This method is much cleaner than writing them out separately as shown below:
.parentA .child {
/* rules here */
}
.parentB .child {
/* rules here */
}
To follow the DRY principle (Don't Repeat Yourself) in CSS, you could utilize SASS or other pre-processors to nest selectors like so:
.parentA, .parentB {
.child {
/* rules here */
}
}
Keep in mind that SASS is a CSS pre-processor that translates into standard CSS during compilation.