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

Creating maintainable CSS

Creating maintainable CSS

A high-level overview of how the approaches taken with OOCSS, SMACSS and BEM can help your CSS remain maintainable and reusable for longer.

From a talk given at the Cape Town Front End Developer meetup March 2013

Rich Archer

March 15, 2013
Tweet

Other Decks in Technology

Transcript

  1. ... The Excruciating Kitchen Sink Analogy ... OOCSS, SMACSS, and

    BEM ... “Allow markup to change” ... “Keep your selectors short” ... “Don’t sweat the class names” ... “Be pragmatic” ... “Extend your modules” ... “Layout modules” ... Style Guides ... Homework/Beer Creating maintainable CSS
  2. CSS makes it easy for us to be stupid #content.box

    { ... } #wrapper #content.box { ... } #i-mean-it-this-time #wrapper #content.box { ... }
  3. Keep your selectors short ...easier debugging ...easier point of entry

    ...avoid speci!city issues ...CSS evaluates right-to-left ...performance?
  4. h1 { font-size: 36px; } h2 { font-size: 24px; }

    #sidebar li a, h3 { font-size: 18px; }
  5. .heading-headline { font-size: 36px; } .heading-subheadline { font-size: 24px; }

    .heading-byline { font-size: 18px; } .theme-summer { color: gold; } .theme-autumn { color: burlywood; } .theme-winter { color: blue; } Combinations of modules
  6. Performance boost? ...reuse of code ...smaller CSS !les ...faster download

    ...less to parse ...combine modules for free varieties
  7. .messagebox { border: 1px solid black; color: white; background: green;

    } .mildalert { border: 1px solid black; color: white; background: orange; } .badalert { border: 1px solid black; color: white; background: red; }
  8. <div class="messagebox"></div> <div class="messagebox messagebox-mild"></div> <div class="messagebox messagebox-bad"></div> .messagebox {

    border: 3px solid black; color: white; background: green; } .messagebox-mild { background: orange; } .messagebox-bad { background: red; }
  9. Easier organisation ...Easier to !nd relevant code ...Less “where should

    this rule go?” ...More predictable ...More maintainable ...Easier debugging ...Faster development
  10. Module Layout Handles positioning only. Twitter Bootstrap sca!olding, OOCSS, 960gs

    Base Browser resets, basic typography, element styles .button, .messageBox, .search-item
  11. Site-speci"c style guides ...a CSS component example page ...uses live

    CSS ...acts as crib sheets for newbies ...single page to check for modi!cations
  12. Useful links Rich Archer @slocombe [email protected] • SMACSS smacss.com •

    OOCSS oocss.org • BEM bem.info • Twitter Bootstrap getbootstrap.com • Jonathan Snook @snookca • Nicolle Sullivan @stubbornella