combination
You don't have to repeat multiple selectors with the same attributes, you just need to separate the selectors with commas (,).
For example, you have the following code:
h2 { color: red; } .thisOtherClass { color: red; } .yetAnotherClass { color: red; } |
Then you can write:
h2, .thisOtherClass, .yetAnotherClass { color: red; } |
Nested
If CSS is well structured, there is no need to use too many classes or identifier selectors. This is because you can specify selectors within selectors. (Or better said, context selector - by translator)
for example:
#top { background-color: #ccc; padding: 1em } #top h1 { color: #ff0; } #top p { color: red; font-weight: bold; } |
This eliminates unnecessary class or identifier selectors if applied to HTML like this:
<div id="top"> <h1>Chocolate curry</h1> <p>This is my recipe for making curry purely with chocolate</p> <p>Mmm mm mmmmm</p> </div> |