Simple class selectors
One of the most prolific ideals of good CSS today is the widespread use of classes in selectors. Classes are easy to read, perform great in browsers, and can be easily structured into components.
Sticking to classes for selectors normalizes the levels of specificity in your CSS. Since each class has the same level of specificity, the only thing that determines it’s ability to override other styles is that selector’s placement in the stylesheet.
Writing those classes well means abiding by a few structural rules. For example:
- Use a single dash between important keywords.
- Don’t chain classes—that increases specificity and dilutes the focus on building components.
Putting those to use looks something like this:
// Basic class structure
.component {}
.component-modifier {}
.component-subcomponent {}
.component-subcomponent-modifier {}
// In practice...
.tabs {}
.tabs-link {}
And in your markup:
<!-- Structure it like this... -->
<ul class="tabs">
<li><a class=“tabs-link“ href="#">...</a></li>
</ul>
<!-- Or like this! -->
<nav class="tabs">
<a class="tabs-link" href="#">...</a>
</nav>