The key selector in CSS is the rightmost selector in any rule. It is the selector upon which the enclosed property/values are applied.
We want our CSS rules to be as flat as possible. We DO NOT want other selectors before a key selector (or any DOM element) unless we absolutely need them to override the default key selector styles.
The reason being that adding additional selectors and using element types (for example h1.yes-This_Selector
):
Creates additional unneeded specificity
Makes it harder to maintain, as subsequent overrides need to be ever more specific
Adds unneeded bloat to the resultant CSS file
In the case of element types, ties the rule to a specific element and/or markup structure
For example, suppose we have a CSS rule like this:
#notMe .or-me [data-thing="nope"] .yes-This_Selector { width: 100%; }
In that above example, yes-This_Selector
is the key selector. If those property/values should...