In css, I have seen both div.selector and selector being used to define styling rules for a specific selector.
What’s the difference between the two and what are the reasons I should consider when adopting one over the other when writing my own css files?
div.selectortargets onlydivelements with a class ofselector..selectortargets ALL elements with a class of.selectornot justDIVsSo prefix element with tag name if you KNOW that’s the one you will be applying css to. The later approach is more generic and targets all elements with specified class. However, you should be specific whenever you can.
If you know only
divelements will have.selectorclass, going specific is better in terms of performance egdiv.selectorrather than.selectorwhich will look for all elements on the page but will eventually apply those styles toDIVsonly.