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

CSS Trickery at the BBC - 2016 - MMU

Shaun Bent
February 17, 2016

CSS Trickery at the BBC - 2016 - MMU

What are challenges of working with CSS at scale? How we implement CSS at the BBC Sport by combining several techniques and approaches including OOCSS, BEM and ITCSS.

Shaun Bent

February 17, 2016
Tweet

More Decks by Shaun Bent

Other Decks in Technology

Transcript

  1. CSS

  2. Old Can’t be changed Global namespace Inheritance based Very, very

    loose Source order critical Cascade needs managing
  3. It doesn’t matter how well-considered your source order is; how

    well you’re utilising the cascade; what naming conventions you use; specificity can undo everything.
  4. Treat CSS like no other language Focus on the wrong

    things Lack of structure Adding new styles to the end of stylesheets Lack of knowledge
  5. “Smart people on great teams cede to the fact that

    they are afraid of their own CSS. You can't just delete things as it's so hard to know if it's absolutely safe to do that.” Chris Coyier
  6. CSS Preprocessor Put Sass in, get CSS out Variables, Functions,

    Mixins, Loops, Logic & Magic Massively helps with working at scale
  7. // Colour them $sport-yellow: #ffdf43; $news-red: #bb1919; $iplayer-pink: #f54997; $live-blue:

    #1169f6; $gel-orange: #e4712a; // Map them $products: ( 'sport': $sport-yellow, 'news': $news-red, 'iplayer': $iplayer-pink, 'live': $live-blue, 'gel': $gel-orange ); // Loop them @each $product-name, $product-colour in $products { .button--#{$product-name} { background-color: $product-colour; } } (22 lines)
  8. // Colour them $sport-yellow: #ffdf43; $news-red: #bb1919; $iplayer-pink: #f54997; $live-blue:

    #1169f6; $gel-orange: #e4712a; // Output them .button--sport { background-color: $sport-yellow; } .button--news { background-color: $news-red; } .button--iplayer { background-color: $iplayer-pink; } .button--live { background-color: $live-blue; } .button--gel { background-color: $gel-orange; } (12 lines)
  9. I love Sass but don’t over do it Less useful

    than a knowledge of architecture Makes nothing better, only faster to write Still only generating CSS
  10. <div class=“o-media"> <div class=“o-media__img”> … </div> <div class=“o-media__body"> … </div>

    </div> .o-media { @include clearfix; display: block; } .o-media__img { float: left; margin-right: 16px; } .o-media__body { display: block; overflow: hidden; }
  11. BEM

  12. More than just a naming convention …although thats probably the

    best part Transparent Readable More useful in HTML than it is in CSS
  13. Settings - global variables, colour swatches Tools - default mixins

    and functions Generic - ground zero styles (resets, normalise, etc) Base - unclassed HTML elements (type selectors) Objects - cosmetic free design abstractions Components - designed components, chucks of UI Utilities - helpers and overides
  14. Everything has a place to live People know where to

    look to find things Sane source order Reduced waste/redundancy Increased scalability Tamed specificity
  15. Criteria of a component ..is a discrete custom element of

    the UI? ..encloses specific semantics and styling? ..can exist completely stand-alone?