Slide 1

Slide 1 text

Getting Sassy with CSS Erin Smith

Slide 2

Slide 2 text

What we are covering: What are CSS preprocessors What advantages do they have How to get set up to use them yourself

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Input Output

Slide 6

Slide 6 text

Basics .scss .sass Uses CSS syntax Indentation instead of brackets Newlines instead of semicolons Other modifications Can be easier to read and write

Slide 7

Slide 7 text

$variables

Slide 8

Slide 8 text

SCSS CSS $yellow: #fce473; .quote { border-left: 5px solid $yellow; } .quote { border-left: 5px solid #fce473; }

Slide 9

Slide 9 text

SCSS CSS $yellow: #fce473; $pink: #c71585; $green: #32cd32; $blue: #1d90ff; $primary-color: $green; .quote { border-left: 5px solid $primary-color; } .button { background: $primary-color; } .sidebar a:hover { border-bottom-color: $primary-color; } .footer a { color: $primary-color; } .quote { border-left: 5px solid #32cd32; } .button { background: #32cd32; } .sidebar a:hover { border-bottom-color: #32cd32; } .footer a { color: #32cd32; }

Slide 10

Slide 10 text

SCSS CSS $yellow: #fce473; $pink: #c71585; $green: #32cd32; $blue: #1d90ff; $primary-color: $pink; .quote { border-left: 5px solid $primary-color; } .button { background: $primary-color; } .sidebar a:hover { border-bottom-color: $primary-color; } .footer a { color: $primary-color; } .quote { border-left: 5px solid #c71585; } .button { background: #c71585; } .sidebar a:hover { border-bottom-color: #c71585; } .footer a { color: #c71585; }

Slide 11

Slide 11 text

Math

Slide 12

Slide 12 text

$numPerRow: 4; $margin: 2%; width: ((100% - (($numPerRow - 1) * $margin)) / $numPerRow);

Slide 13

Slide 13 text

Nesting

Slide 14

Slide 14 text

SCSS CSS nav { ul { margin: 0; padding: 0; list-style: none; } li { display: inline-block; } a { display: block; padding: 6px 12px; text-decoration: none; } } nav ul { margin: 0; padding: 0; list-style: none; } nav li { display: inline-block; } nav a { display: block; padding: 6px 12px; text-decoration: none; }

Slide 15

Slide 15 text

@imports

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

SCSS //main.scss /* base */ @import “base/reset”; @import “base/typography”; /* components */ @import “components/buttons”; @import “components/nav”; @import “components/dropdown”; |— base/ | |— _reset.scss #Reset/normalize | |— _typography.scss #Typography rules | |— components/ | |— _buttons.scss #Buttons | |— _navigation.scss #Navigation | |— _dropdown.scss #Dropdown

Slide 18

Slide 18 text

@mixins

Slide 19

Slide 19 text

SCSS CSS @mixin overlay() { bottom: 0; left: 0; position: absolute; right: 0; top: 0; } .modal-background { @include overlay(); background: black; opacity: 0.9; } .modal-background { bottom: 0; left: 0; position: absolute; right: 0; top: 0; background: black; opacity: 0.9; }

Slide 20

Slide 20 text

SCSS CSS @mixin overlay() { bottom: 0; left: 0; position: absolute; right: 0; top: 0; } .modal-background { @include overlay(); background: black; opacity: 0.9; } .product-link { @include overlay(); background: blue; opacity: 0.6; } .modal-background { bottom: 0; left: 0; position: absolute; right: 0; top: 0; background: black; opacity: 0.9; } .product-link { bottom: 0; left: 0; position: absolute; right: 0; top: 0; background: blue; opacity: 0.6; }

Slide 21

Slide 21 text

SCSS CSS @mixin border-radius($radius) { -webkit-border-radius: $radius; -moz-border-radius: $radius; -ms-border-radius: $radius; border-radius: $radius; } .box { @include border-radius(3px); } .box { -webkit-border-radius: 3px; -moz-border-radius: 3px; -ms-border-radius: 3px; border-radius: 3px; }

Slide 22

Slide 22 text

$numPerRow: 4; $margin: 2%; width: ((100% - (($numPerRow - 1) * $margin)) / $numPerRow); @mixin columnMaker($numPerRow, $margin) { width: ((100% - (($numPerRow - 1) * $margin)) / $numPerRow); &:nth-child(n) { margin-bottom: $margin; margin-right: $margin; } &:nth-child(#{$numPerRow}n) { margin-right: 0; margin-bottom: 0; } }

Slide 23

Slide 23 text

@extend

Slide 24

Slide 24 text

SCSS CSS %message-shared { border: 1px solid #ccc; padding: 10px; color: #333; } %equal-heights { display: flex; flex-wrap: wrap; } .success { @extend %message-shared; border-color: green; } .error { @extend %message-shared; border-color: red; } .warning { @extend %message-shared; border-color: yellow; } .success, .error, .warning { border: 1px solid #ccc; padding: 10px; color: #333; } .success { border-color: green; } .error { border-color: red; } .warning { border-color: yellow; }

Slide 25

Slide 25 text

@extend - rulesets are inherently related - near to each other in the code @mixin - inject dynamic values into repeated construct - Sassy copy/paste

Slide 26

Slide 26 text

Loops

Slide 27

Slide 27 text

@if @for @each @while

Slide 28

Slide 28 text

SCSS CSS $list: adam john wynn mason kuroir; @mixin author-images { @each $author in $list { .photo-#{$author} { background: image-url(‘/images/#{$author}.png’) no-repeat; } } } .author-bio { @include author-images; } .author-bio .photo-adam { background: url(‘/images/adam.png’) no-repeat; } .author-bio .photo-john { background: url(‘/images/adam.png’) no-repeat; } .author-bio .photo-wynn { background: url(‘/images/adam.png’) no-repeat; } .author-bio .photo-mason { background: url(‘/images/adam.png’) no-repeat; } .author-bio .photo-kuroir { background: url(‘/images/adam.png’) no-repeat; }

Slide 29

Slide 29 text

Pre-built Functions

Slide 30

Slide 30 text

lighten($color, $amount) grayscale($color) complement($color) unquote($string) to-upper-case($string) random()

Slide 31

Slide 31 text

$notification-confirm: hsla(101, 72%, 37%, 1); $notification-warning: #ffc53a; $notification-alert: rgb(172, 34, 34); %notification { border-radius: 10px; display: block; font-size: 1.5em; font-family: sans-serif; padding: 1em 2em; margin: 1em auto; width: 30%; text-align: center; } SCSS

Slide 32

Slide 32 text

@function set-notification-text-color($color) { @if (lightness($color) > 50) { @return #000000; } @else { @return #ffffff; } } .notification { @extend %notification; } .notification-confirm { background: $notification-confirm; color: set-notification-text-color($notification-confirm); } .notification-warning { background: $notification-warning; color: set-notification-text-color($notification-warning); } .notification-alert { background: $notification-alert; color: set-notification-text-color($notification-alert); } SCSS

Slide 33

Slide 33 text

Getting Started WordPress.com Plugin WP-SCSS Command Line NPM: nom install -g sass Chocolatey: choco install sass Homebrew: brew install sass/sass/sass sass styles.scss styles.css Application CodeKit Compass.app Koala PHPStorm

Slide 34

Slide 34 text

Resources: sass-lang.com marksheet.io thesassway.com sassisfaction.com