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

Modular Front-End Development With Sass & BEM

Modular Front-End Development With Sass & BEM

A talk given to the students of the University of Gloucestershire on March 14th 2016. It was part of their "WebX" event where they invited people from industry to give talks to enhance their learning.

hankchizljaw

March 14, 2016
Tweet

Other Decks in Education

Transcript

  1. Sass file (e.g. cat.scss) Compiler (e.g. Grunt/Gulp, CodeKit, Prepros) CSS

    File is produced and is read by the browser as usual
  2. <figure class="cat"> <img src="/cat.jpg" alt="Cat wants some tuna" /> <figcaption>

    Image courtesy cheeseburger.com </figcaption> </figure> The Old Way: HTML
  3. .cat { ... } .cat img { ... } .cat

    figcaption { ... } The Sass Way: CSS
  4. @mixin caption($is_italic: false) { color: $dark-grey; display: block; padding: 5px

    5px; @if($is_italic) { font-style: italic; } } The Sass Way: SCSS
  5. .cat { ... img { ... } figcaption { @include

    caption(true); } } The Sass Way: SCSS
  6. <figure class="cat cat--large"> <img src="/cat.jpg" class="cat__image" /> <figcaption class="cat__caption"> Image

    courtesy cheeseburger.com </figcaption> </figure> The BEM Way: HTML BLOCK MODIFIER ELEMENT
  7. 2. Clear HTML to partial & module relationship Markup can

    be different from instance to instance 1.
  8. <div class="cat"> <img src="/cat.jpg" class="cat__image" /> <p class="cat__caption"> Image courtesy

    cheeseburger.com </p> </div> Markup can be different from instance to instance: HTML
  9. <header class="headline"> <h1 class="headline__heading"> A top level heading </h1> </header>

    <header class="headline"> <h2 class="headline__heading"> A second level heading </h2> </header> Markup can be different from instance to instance: HTML
  10. 2. Clear HTML to partial & module relationship Markup can

    be different from instance to instance 1.
  11. <figure class="cat cat--large"> <img src="/cat.jpg" class="cat__image" /> <figcaption class="cat__caption"> Image

    courtesy cheeseburger.com </figcaption> </figure> The BEM Way: HTML BLOCK MODIFIER ELEMENT
  12. Using Sass helps us to create smaller partials & modules

    that compile to one file. This helps create a manageable codebase.
  13. Using BEM can help expand on that by allowing us

    to write flexible markup with a clear path to the module or partial.