2 ms·
> Only use the ID selector in your CSS as a last resort to fix > extreme and hard-to-solve specificity issues. Try doubling up on a > class first. .class.cl
by dotancohen 5y ago
> Only use the ID selector in your CSS as a last resort to fix
> extreme and hard-to-solve specificity issues. Try doubling up on a
> class first. .class.class is a valid selector and can work wonders.
Someone is going to have to justify this. What does .class.class do, and how could that be better than #id?
- tdrdt 5y ago"What does .class.class do" It selects elements with the class `class` that also have the class `class`. The example might be a little abstract but it could be something like `.message.highlight`, which selects all elements with the class `message` that also have the class `highlight`. Classes are for classification, IDs are identification. For styling you almost never need identifiers because that is not what styling is about. <div class="message highlight"> .message.highlight {} is much better than <div id="highlightMessage"> #highlightMessage {} IDs are like singletons: not reusable.
- dotancohen 5y agoI see, so he is suggesting `div.foo.bar`, not `div.foo.foo` which is how I understood it.