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

RSCSS: Writing CSS without losing your sanity

Rico Sta. Cruz
November 10, 2015

RSCSS: Writing CSS without losing your sanity

First presented at MelbCSS Nov 2015.

Rico Sta. Cruz

November 10, 2015
Tweet

More Decks by Rico Sta. Cruz

Other Decks in Technology

Transcript

  1. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU Modern CSS makes it easy

    to style components, such as this one. However, not everyone writes CSS the same way. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU UIIUIUIN UIIU UIUNUN INU UIN
  2. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU HTML makes it intuitive to

    write classes and nest them properly. article
  3. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU HTML makes it intuitive to

    write classes and nest them properly. article div.image
  4. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU HTML makes it intuitive to

    write classes and nest them properly. article div.heading div.image
  5. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU HTML makes it intuitive to

    write classes and nest them properly. article div.heading div.description div.image
  6. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU HTML makes it intuitive to

    write classes and nest them properly. article div.heading div.description div.actions div.image
  7. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU HTML makes it intuitive to

    write classes and nest them properly. article div.heading div.description div.actions div.image img
  8. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU HTML makes it intuitive to

    write classes and nest them properly. article div.heading div.description div.actions div.image img h2.title h2.description
  9. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU HTML makes it intuitive to

    write classes and nest them properly. article div.heading div.description div.actions div.image img h2.title h2.description p
  10. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU HTML makes it intuitive to

    write classes and nest them properly. article div.heading div.description div.actions div.image img h2.title h2.description p a.button
  11. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU article div.image img div.heading h2.title

    h2.description div.description p div.actions a.button "Semantic"
  12. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU .photo-card { .image { ...

    } .text { padding: 24px; .heading { font-size: 2em; } } }
  13. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU .photo-card { .image { ...

    } .text { padding: 24px; .heading { font-size: 2em; @media (min-width: 768px) { font-size: 3em; } } } }
  14. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU .photo-card { .image { ...

    } .text { padding: 24px; .heading { font-size: 2em; @media (min-width: 768px) { font-size: 3em; } } .subheading { font-size: 2em; @media (min-width: 768px) { font-size: 3em; } } } }
  15. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU article div.image img div.heading h2.title

    h2.description div.description p div.actions a.button "Semantic" The naïve approach
  16. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU .photo-card { .photo { img

    { ... } } .text { .heading { .title { ... } .subtitle { ... } } .description { p { ... } } .action { .btn { ... } } } } Over-nesting is a common problem with this approach, though. CSS becomes hard to read.
  17. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU BEM Makes this a little

    easier. .photo_card .photo_card--photo .photo_card--heading .photo_card--subheading .photo_card--description .photo_card--action
  18. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU BEM Makes this a little

    easier. Block Element .photo_card .photo_card--photo .photo_card--heading .photo_card--subheading .photo_card--description .photo_card--action
  19. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU .photo_card { &--photo { ...

    } &--heading { ... } &--subheading { ... } &--description { ... } &--action { ... } } BEM Makes this a little easier.
  20. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU It comes at the price

    of dirtier markup. <div class='photo-card'> <div class='photo-card--photo'> <img src='foo.jpg' class='photo-card--image'> </div> <div class='photo-card--text'> <h2 class='photo-card--heading'>...</h2> <p class='photo-card--subheading'>...</p> </div> <div class='photo-card--description'> <p>...</p> </div> <div class='photo-card--actions'> <a class='photo-card--button'></a> </div> </div> UIIUIUIN UIIUNIUN UIUNUN INU UINUIU UIIUIUIN UIIU UIUNUN INU UIN
  21. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU Bootstrap has its own convention

    in class names. .panel .panel-head .panel-body .btn .btn-primary .btn-small UIIUIUIN UIIUNIUN UIUNUN INU UINUIU UIIUIUIN UIIU UIUNUN INU UIN
  22. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU Bootstrap's approach is almost equivalent

    to BEM, anyway. .photo-card .photo-card-photo .photo-card-heading .photo-card-subheading .photo-card-description .photo-card-action
  23. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU Bootstrap's approach is almost equivalent

    to BEM, anyway. Block Element .photo-card .photo-card-photo .photo-card-heading .photo-card-subheading .photo-card-description .photo-card-action
  24. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU .photo-card What if... there's a

    way to keep this semantic structure, yet have clean CSS?
  25. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU .photo-card .image What if... there's

    a way to keep this semantic structure, yet have clean CSS?
  26. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU .photo-card .heading .image What if...

    there's a way to keep this semantic structure, yet have clean CSS?
  27. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU .photo-card .heading .description .image What

    if... there's a way to keep this semantic structure, yet have clean CSS?
  28. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU .photo-card .heading .description .actions .image

    What if... there's a way to keep this semantic structure, yet have clean CSS?
  29. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU .photo-card .heading .description .actions .image

    .title .description What if... there's a way to keep this semantic structure, yet have clean CSS?
  30. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU .photo-card .heading .description .actions .image

    .title .description .button What if... there's a way to keep this semantic structure, yet have clean CSS?
  31. UIIUIUIN UIIUNIUN UIUNUN INU UINUIU .photo-card { > .image {

    ... } > .heading { ... } > .action { ... } > .action > .btn { ... } }