This rule compares your current CSS selectors against a list of preferred styles. It reports situations where a selector can be rewritten using a more preferred style from your configuration.
Note on selector capabilities:
- Class selectors (
.link) can be used in almost any situation. - ID selectors (
#link) can only be used to select a single element. - Type selectors (
a) are only applicable when selecting all elements of that specific type.
Because of these constraints, the rule only suggests rewrites that are functionally equivalent.
Usage Example
Given the preference ["type", "id", "class"]:
<a class="link" id="firstLink">Click me!</a>
<b class="bold cross">Text one</b>
<i id="italic">Text three</i>
<style>
/* ✓ GOOD: Matches preferred order */
a { color: green; }
#firstLink { color: green; }
.cross { color: green; }
/* ✗ BAD: Can be rewritten to a more preferred style */
/* Can use a type selector instead of a class */
.link { color: red; }
/* Can use an ID selector instead of a class */
.bold { color: red; }
/* Can use a type selector instead of an ID */
#italic { color: red; }
</style>
<style>
/* ✓ GOOD */
a { color: green; }
#firstLink { color: green; }
.cross { color: green; }
/* ✗ BAD */
.link { color: red; } /* Can use a type selector */
.bold { color: red; } /* Can use an ID selector */
#italic { color: red; } /* Can use a type selector */
</style>