Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Organizing CSS: OOCSS, SMACSS, and BEM

Organizing CSS: OOCSS, SMACSS, and BEM

"Organizing CSS" talk, local meetup version
Gainesville Frontend Awesome - February 19, 2015

See related blog post:
http://mattstauffer.co/blog/organizing-css-oocss-smacss-and-bem

Matt Stauffer

February 19, 2015
Tweet

More Decks by Matt Stauffer

Other Decks in Programming

Transcript

  1. Who am I? Matt Stauffer Partner & Technical Director, Tighten

    Co. Writer/Blogger/Teacher ’n’ Stuff @stauffermatt @stauffermatt - Frontend-Awesome Meetup, February 19, 2015
  2. Learn from OBJECT-ORIENTED PROGRAMMING ▸ Decoupling ▸ Single Responsibility Principle

    & Separation of Concerns ▸ Encapsulation @stauffermatt - Frontend-Awesome Meetup, February 19, 2015
  3. THE BASICS OF OOCSS ▸ Identify patterns and “objects” (or

    “modules”) in your code ▸ Nicole Sullivan’s Media Object @stauffermatt - Frontend-Awesome Meetup, February 19, 2015
  4. THE BASICS OF SMACSS ▸ Base: applies to HTML, no

    class/ID selectors ▸ Layout: big page sections—.header, .sidebar, etc. ▸ Module: encapsulated modeles, re-usable ▸ State: overrides defaults—e.g. .is-opened ▸ Theme: optional, if theming needed @stauffermatt - Frontend-Awesome Meetup, February 19, 2015
  5. THE BASICS OF BEM ▸ Naming convention for modular/object-oriented CSS

    ▸ .{Block}__{Element} ▸ .{Block}__{Element}--{Modifier} ▸ .{Block}--{Modifier} @stauffermatt - Frontend-Awesome Meetup, February 19, 2015
  6. BEM WITH Sass /* Sass 3.3+ w/BEM: */ .object {

    color: red; &__descendant { color: black; } } /* Generates: .object { color: red; } .object__descendant { color: black } */ @stauffermatt - Frontend-Awesome Meetup, February 19, 2015
  7. BEM WITH LESS /* LESS w/BEM: */ .object { color:

    red; &__descendant { color: black; } } /* Generates: .object { color: red; } .object__descendant { color: black } */ @stauffermatt - Frontend-Awesome Meetup, February 19, 2015
  8. BUT WHAT ABOUT UTILITY CLASSES? <div class="pull-left col-md-6 small"> </div>

    THE PROBLEM: UTILITY CLASSES TIE YOUR MARKUP TO PRESENTATION @stauffermatt - Frontend-Awesome Meetup, February 19, 2015
  9. Solutions: 1. BOOTSTRAP WITHOUT THE DEBT: Sass @extend .primary-rail {

    @extend .pull-left, .col-md-6, .small; } 2. LESS @import (reference) 3. BUILD WITH UTILITY, EXTRACT COMPONENTS AS NECESSARY @stauffermatt - Frontend-Awesome Meetup, February 19, 2015
  10. HOW TO GET STARTED ▸ flatten selectors ▸ organize your

    code ▸ make your classes Do One Thing Well™ ▸ decouple for reusability ▸ try a preprocessor @stauffermatt - Frontend-Awesome Meetup, February 19, 2015