requiring intimate knowledge of the HTML. ✦ Too much “presentation” in the HTML. ✦ HTML elements with the sole purpose of providing CSS hooks. Why is this happening?
and element defaults Layout Positioning of site-wide elements and generic layout helpers like grids Modules Reusable visual elements State Toggled states of layout or modules (via JavaScript) Theme (optional) Look and feel http://smacss.com
styles When we see a class in HTML, you should be able to instantly understand it’s purpose. Class of unknown purpose in HTML Should we remove it? Namespace classes Perhaps use <div class="js-class-name"> to separate presentation and behavior.
.button-group { } /* A component modifier for .button? */ .button-primary { } /* A component sub-component within .button? */ .button-icon { } /* Is this a component class or a layout class? */ .header { }
✦ Don’t use non-semantic type selectors (e.g. DIV, SPAN) in any multi-part rule. ✦ Don’t use more than 2 combinators in a selector. ✦ Don’t allow any class names that begin with “js-”. ✦ Warn if frequently using layout and positioning for non “l-” prefixed rules. ✦ Warn if a class defined by itself is later redefined as a child of something else.
OOP, DRY, the open/closed principle, separation of concerns, etc. still apply to CSS. ✦ Judge your organizational methods by whether they make development more efficient long-term. ✦ Strive for CSS that is predictable, reusable, maintainable, and scaleable.
article on CSS Architecture. While I have been preaching many of these techniques for years, Philip laid out the arguments, techniques, and examples in a wonderful article. Thanks Philip. http://engineering.appfolio.com/2012/11/16/css-architecture