While developing websites with Drupal, it's common to get really complex selectors (especially with menu styling.)
There are 2 reasons for this:
- We are overriding CSS rules in core that are already complex.
- We have no easy classes to match exactly what we want.
While reading about the SMACSS technique, the class naming technique made a lot of sense. It uses modular class names. Related components get class names that include both the component name and the variant name.
.COMPONENT
.COMPONENT--VARIANT
.COMPONENT__SUB-ELEMENT
.COMPONENT--VARIANT__SUB-ELEMENT
For example, instead of ul li.expanded we should just use .menu__item-expanded.
Sub-issues:
#1713168: Add SMACSS-style classes to header
#1713170: Add SMACSS-style classes to menus
#1713172: Add SMACSS-style classes to tabs
#1713320: Add SMACSS-style classes to messages
#1714986: Add SMACSS-style rulesets to pager
#1719726: Simplify various selectors to use SMACSS-style classes
Comments
Comment #0.0
johnalbinAdd example
Comment #0.1
johnalbinAdd sub-issues
Comment #0.2
johnalbinAdd sub-task
Comment #1
johnalbinThe class names are all off. They should follow the standards we developed for Drupal 8, so I've updated the issue summary.
I need to roll-back some of those sub-issues in the 7.x-5.x branch.
Comment #1.0
johnalbinAdd new sub-task
Comment #2
johnalbinThe partial rollbacks are a duplicate of #1961360: Component element and modifier delimiters don't match Drupal 8’s convention
Comment #3.0
(not verified) commentedUpdate component class naming examples.