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

Intro to Sass

Intro to Sass

Curious about preprocessors? Meet Sass, the most mature, stable, and powerful professional grade CSS extension language in the world. I'll go through the basics and show you how Sass can give you CSS superpowers, both for small and large scale projects.

Slides from Devstaff meetup in Heraklion, Greece.

Zaharenia Atzitzikaki

October 13, 2016
Tweet

More Decks by Zaharenia Atzitzikaki

Other Decks in Programming

Transcript

  1. CSS .module { ... } .module .title { ... }

    .module .title span { ... } .module .footer { ... }
  2. Sass // SCSS syntax $color: #f00; .link { color: $color;

    text-decoration: underline; &:hover { text-decoration: none; } } // Sass syntax $color: #f00 .link color: $color text-decoration: underline &:hover text-decoration: none
  3. Sass .modal { background-color: #fff; border: 1px solid rgba(0, 0,

    0, 0.3); .modal-header { padding: 15px 20px; border-bottom: 1px solid #eee; } .modal-footer { padding: 14px 15px 15px; text-align: center; } }
  4. CSS .modal { background-color: #fff; border: 1px solid rgba(0, 0,

    0, 0.3); } .modal .modal-header { padding: 15px 20px; border-bottom: 1px solid #eee; } .modal .modal-footer { padding: 14px 15px 15px; text-align: center; }
  5. Sass body { .container { .content { .articles { &

    > .post { .title { h1 { a { } } } .content { p { ... } ul { li { ... } }
  6. Sass } h4 { a { ... } } p

    { a { ... } } ul { li { ... } } } } } } } }
  7. Sass .box { .box-section a { color: fuchsia; text-decoration: none;

    &:hover { text-decoration: underline; } &.disabled { color: grey; } } }
  8. CSS .box .box-section a { color: fuchsia; text-decoration: none; }

    .box .box-section a:hover { text-decoration: underline; } .box .box-section a.disabled { color: grey; }
  9. .box { … &-header { … } } .box {

    … } .box-header { … }
  10. .box { … .checkout & { … } } .box

    { … } .checkout .box { … }
  11. .box { … & + & { … } }

    .box { … } .box + .box { … }
  12. Sass @mixin box { background-color: #fff; border: 1px solid #ccc;

    border-radius: 4px; width: 100px; height: 100px; } .box { @include box; }
  13. Sass @mixin box($width, $height: $width) { background-color: #fff; border: 1px

    solid #ccc; border-radius: 4px; width: $width; height: $height; } .box { @include box(100px, 300px); }
  14. Sass .alert { padding: 15px; font-size: 1.2em; line-height: 1; color:

    #fff; background: $color-accent; @include shadow(0, 1px, 2px, rgba(0,0,0,.5)); @include rounded(10px); } .alert-positive { background: #9c3; } <div class="alert alert-positive">...</div>
  15. Sass .alert { padding: 15px; font-size: 1.2em; line-height: 1; color:

    #fff; background: $color-accent; @include shadow(0, 1px, 2px, rgba(0,0,0,.5)); @include rounded(10px); } .alert-positive { @extend .alert; background: #9c3; } <div class="alert-positive">...</div>
  16. CSS .alert, .alert-positive { padding: 15px; font-size: 1.2em; line-height: 1;

    color: #fff; background: yellow; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); border-radius: 10px; } .alert-positive { background: #9c3; }
  17. Sass .top-navigation, .subnav, .sidenav, #header, .main-footer, .inbox__actions, .feed__item__selector input[type="checkbox"], .feed__item__main

    .avatar, .feed__item__main .control-faux, .feed__item__actions, .feed__item__title .js-visibility, .feed__item__preview__text, .scroll-shelf, .profile__toolbar, .profile__footer, .profile__section__header .download, .overlay__shelf,
  18. Sass %alert { padding: 15px; font-size: 1.2em; line-height: 1; color:

    #fff; background: $color-accent; @include shadow(0, 1px, 2px, rgba(0,0,0,.5)); @include rounded(10px); } .alert-positive { @extend %alert; background: #9c3; } .alert-negative { @extend %alert; background: #c00; }
  19. Sass .alert-positive, .alert-negative { padding: 15px; font-size: 1.2em; line-height: 1;

    color: #fff; background: $color-accent; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); border-radius: 10px; } .alert-positive { background: #9c3; } .alert-negative { background: #c00; }
  20. Sass %alert { padding: 15px; font-size: 1.2em; line-height: 1; color:

    #fff; @include shadow(0, 1px, 2px, rgba(0,0,0,.5)); @include rounded(10px); } .alert-positive { @extend %alert; background: #9c3; } .alert-negative { @extend %alert; background: #c00; }
  21. CSS .alert-positive, .alert-negative { padding: 15px; font-size: 1.2em; line-height: 1;

    color: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); border-radius: 10px; } .alert-positive { background: #9c3; } .alert-negative { background: #c00; }
  22. Sass @mixin alert($background: "yellow") { padding: 15px; font-size: 1.2em; line-height:

    1; color: #fff; background: $background; @include shadow(0, 1px, 2px, rgba(0,0,0,.5)); @include rounded(10px); } .alert-positive { @include alert(#9c3); } .alert-negative { @include alert(#c00); }
  23. CSS .alert-positive { padding: 15px; font-size: 1.2em; line-height: 1; color:

    #fff; background: #9c3; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); border-radius: 10px; } .alert-negative { padding: 15px; font-size: 1.2em; line-height: 1; color: #fff; background: #c00; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); border-radius: 10px; }
  24. Sass $grid-columns: 12; $grid-width: 960px; @function columns($cols) { @return (($grid-width

    / $grid-columns) * $cols) + “px”; } main { width: columns(9); // 720px } aside { width: columns(3); // 240px }
  25. Sass @function black($opacity) { @return rgba(0, 0, 0, $opacity); }

    @function white($opacity) { @return rgba(255, 255, 255, $opacity); } .faded-text { color: black(0.5); } .faded-panel { background-color: white(0.3); }
  26. Sass @mixin gradient-vertical($start-color: #555, $end-color: #333) { background-color: mix($start-color, $end-color,

    60%); background-image: linear-gradient(to bottom, $start-color, $end-color); background-repeat: repeat-x; } .box { @include gradient-vertical(#f8af1e, #097380); } mix
  27. Sass $variable: "hi!"; /* This is a comment which can

    span * several lines. * It can also make use of variables! #{$variable} */ .box { ... } // This is a single-line comment // It won't appear in the CSS output 
 a { ... }