Slide 1

Slide 1 text

CSS PRE-PROCESSORS Sass / Less / Stylus

Slide 2

Slide 2 text

TOPICS 1. What is a preprocessor 2. Preprocessors (Less, Sass, Stylus) 3. Setup 4. Features (beginner, intermediate, advanced) 5. Frameworks

Slide 3

Slide 3 text

CSS PRE-PROCESSORS What is a Preprocessor?

Slide 4

Slide 4 text

@bermonpainter #teamsass

Slide 5

Slide 5 text

master.scss _normalize.scss _typography.scss _grid.scss _modules.scss _theme.scss master.css

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

CSS PRE-PROCESSORS If you write sucky CSS, a pre-processor won’t make it suck less.

Slide 10

Slide 10 text

QUICK START

Slide 11

Slide 11 text

GUI APPS

Slide 12

Slide 12 text

QUICK START

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

COMMAND LINE

Slide 17

Slide 17 text

COMMAND LINE $ gem install sass $ mv style.css style.scss $ sass style.scss style.css Sass

Slide 18

Slide 18 text

COMMAND LINE $ npm install less $ lessc style.less Less

Slide 19

Slide 19 text

COMMAND LINE $ npm install stylus $ stylus -c style.styl Stylus

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

WISEHEA RT D ESIGN → The designer’s guide to the OSX command prompt A tutorial for the modern web designer The command prompt. Once the lofty domain of that guy you know with the computer science degree. Now more and more the every day domain of the hacker web designer. Perhaps you’ve mastered a little Javascript or PHP, but you are realizing that the cool kids are playing around with stuff that is only accessible to people who are comfortable with the command prompt. Or, perhaps you are just

Slide 25

Slide 25 text

COMPILING

Slide 26

Slide 26 text

COMPILING Local

Slide 27

Slide 27 text

COMPILING On Deploy

Slide 28

Slide 28 text

COMPILING On Request

Slide 29

Slide 29 text

COMPILING On the Client (don’t do this)

Slide 30

Slide 30 text

SYNTAX

Slide 31

Slide 31 text

SYNTAX .widget { margin: 20px 10px; } ! ! .widget margin: 20px 10px Sass

Slide 32

Slide 32 text

SYNTAX .widget { margin: 20px 10px; } Less

Slide 33

Slide 33 text

SYNTAX .widget { margin: 20px 10px; } ! .widget margin 20px 10px Stylus

Slide 34

Slide 34 text

BEGINNER

Slide 35

Slide 35 text

BEGINNER style.css > style.scss | style.less | style.styl Creating a pre-processed file Just change the file extension

Slide 36

Slide 36 text

BEGINNER $colorPrimary: #333; $siteWidth: 960px; ! body { color: $colorPrimary; width: $siteWidth; } Variables – Sass

Slide 37

Slide 37 text

BEGINNER @colorPrimary: #333; @siteWidth: 960px; ! body { color: @colorPrimary; width: @siteWidth; } Variables – Less

Slide 38

Slide 38 text

BEGINNER colorPrimary #333 siteWidth 960px ! body color colorPrimary width siteWidth Variables – Stylus

Slide 39

Slide 39 text

BEGINNER body { color: #333; width: 960px; } Variables – Output

Slide 40

Slide 40 text

BEGINNER nav { width: 200px; }
 nav ul { list-style: none; }
 nav ul li { background: #ccc; } nav ul li a{ color: #333; } Nesting - CSS

Slide 41

Slide 41 text

BEGINNER nav { width: 200px; ! ul { list-style: none; ! li { background: #ccc; ! a {
 color: #ccc; } } } } Nesting - Sass/Less

Slide 42

Slide 42 text

BEGINNER Nesting - Stylus nav width 200px ! ul list-style none ! li background #ccc ! a 
 color #ccc

Slide 43

Slide 43 text

BEGINNER nav { width: 200px; }
 nav ul { list-style: none; }
 nav ul li { background: #ccc; } nav ul li a{ color: #333; } Nesting - Output

Slide 44

Slide 44 text

BEGINNER Nesting Pay attention to specificity

Slide 45

Slide 45 text

BEGINNER nav { width: 200px; ! ul { list-style: none; } li { background: #ccc; } a {
 color: #ccc; } } Nesting - Sass/Less

Slide 46

Slide 46 text

BEGINNER Nesting - Stylus nav width 200px ! ul list-style none ! li background #ccc ! a 
 color #ccc

Slide 47

Slide 47 text

BEGINNER nav { width: 200px; }
 nav ul { list-style: none; }
 nav li { background: #ccc; } nav a{ color: #333; } Nesting - Output

Slide 48

Slide 48 text

BEGINNER nav {
 margin: 0; padding: 20px; a{ color: #000; } a:hover, a:focus { color: #999; } a:active { color: #333; } } Reference Selector

Slide 49

Slide 49 text

BEGINNER nav {
 margin: 0; padding: 20px; a{ color: #000; &:hover, &:focus { color: #999; } ! &:active { color: #333; } } } Reference Selector - Sass/Less

Slide 50

Slide 50 text

BEGINNER nav 
 margin 0 padding 20px ! a color #000 ! &:hover, &:focus color #999 ! &:active color #333 Reference Selector - Stylus

Slide 51

Slide 51 text

BEGINNER nav {
 margin: 0; padding: 20px; } nav a{ color: #000; } nav a:hover, nav a:focus { color: #999; } nav a:active { color: #333; } Reference Selector - Output

Slide 52

Slide 52 text

BEGINNER nav { margin: 0; padding: 20px; ! .ie6 & { padding: 10px; } .ie7 & { padding: 20px; }
 .touch & { width: 100%; } } Reference Selector - Sass/Less

Slide 53

Slide 53 text

BEGINNER nav margin 0 padding 20px ! .ie6 & padding 10px .ie7 & padding 20px 
 .touch & width 100% Reference Selector - Stylus

Slide 54

Slide 54 text

BEGINNER nav { margin: 0; padding: 20px; } .ie6 nav{ padding: 10px; } .ie7 nav { padding: 20px; }
 .touch nav { width: 100%; } Reference Selector - Output

Slide 55

Slide 55 text

master.scss _normalize.scss _typography.scss _grid.scss _modules.scss _theme.scss master.css Title Text @import BEGINNER

Slide 56

Slide 56 text

BEGINNER @import "setup"; @import "reset"; @import "base"; @import "layout"; @import "typography"; @import "theme"; @import – Sass/Less

Slide 57

Slide 57 text

BEGINNER @import "setup" @import "reset" @import "base" @import "layout" @import "typography" @import "theme" @import – Stylus

Slide 58

Slide 58 text

INTERMEDIATE

Slide 59

Slide 59 text

INTERMEDIATE .box { -webkit-border-radius: 5px; -moz-border-radius: 5px; -ms-border-radius: 5px; -o-border-radius: 5px; border-radius: 5px; } Mixins - CSS

Slide 60

Slide 60 text

INTERMEDIATE @mixin border-radius($radius) { -webkit-border-radius: $radius; -moz-border-radius: $radius; -ms-border-radius: $radius; -o-border-radius: $radius; border-radius: $radius; } .box { @include border-radius(5px); } Mixins - Sass

Slide 61

Slide 61 text

INTERMEDIATE .border-radius(@radius) { -webkit-border-radius: @radius; -moz-border-radius: @radius; -ms-border-radius: @radius; -o-border-radius: @radius; border-radius: @radius; } .box { .border-radius(5px); } Mixins - Less

Slide 62

Slide 62 text

INTERMEDIATE border-radius radius -webkit-border-radius radius -moz-border-radius radius -ms-border-radius radius -o-border-radius radius border-radius radius ! .box border-radius 5px Mixins - Stylus

Slide 63

Slide 63 text

INTERMEDIATE .box { -webkit-border-radius: 5px; -moz-border-radius: 5px; -ms-border-radius: 5px; -o-border-radius: 5px; border-radius: 5px; } Mixins - Output

Slide 64

Slide 64 text

INTERMEDIATE .borders { border: 1px solid #efefef; padding: 10px; } p { @extend .borders; font-size: 20px; } ul, ol { @extend .borders; text-transform: uppercase; } @extend – Sass

Slide 65

Slide 65 text

INTERMEDIATE .borders { border: 1px solid #efefef; padding: 10px; } p { &:extend(.borders); font-size: 20px; } ul, ol { &:extend(.borders); text-transform: uppercase; } :extend – Less

Slide 66

Slide 66 text

INTERMEDIATE .borders border 1px solid #efefef padding 10px ! p @extend .borders font-size 20px ! ul, ol @extend .borders text-transform uppercase @extend – Stylus

Slide 67

Slide 67 text

INTERMEDIATE .borders, p, ul, ol { border: 1px solid #efefef; padding: 10px; } p {
 font-size: 20px; } ul, ol { text-transform: uppercase; } @extend – Output

Slide 68

Slide 68 text

INTERMEDIATE %borders { border: 1px solid #efefef; padding: 10px; } p { @extend %borders; font-size: 20px; } ul, ol { @extend %borders; text-transform: uppercase; } @extend + Placeholder – Sass

Slide 69

Slide 69 text

INTERMEDIATE %borders border 1px solid #efefef padding 10px ! p @extend %borders font-size 20px ! ul, ol @extend %borders text-transform uppercase @extend + Placeholder – Stylus

Slide 70

Slide 70 text

INTERMEDIATE p, ul, ol { border: 1px solid #efefef; padding: 10px; } p {
 font-size: 20px; } ul, ol { text-transform: uppercase; } @extend – Stylus

Slide 71

Slide 71 text

ADVANCED

Slide 72

Slide 72 text

ADVANCED $grid-columns: 12; $grid-width: 960px; ! @function calculate-column-width($cols) { @return (($grid-width / $grid-columns) * $cols / $grid-width) * 100%; } ! #container { margin: 0 auto; width: 100%; } article { float: left; width: calculate-column-width(8); } aside { float: right; width: calculate-column-width(4); } Functions – Sass

Slide 73

Slide 73 text

ADVANCED @grid-columns: 12; @grid-width: 960px; ! .calculate-column-width(@cols) { width: (((@grid-width / @grid-columns) * @cols / @grid-width) * 100%); } ! #container { margin: 0 auto; width: 100%; } article { float: left; .calculate-column-width(8); } aside { float: right; .calculate-column-width(4); } Functions – Less

Slide 74

Slide 74 text

ADVANCED grid-columns 12 grid-width 960px ! calculate-column-width(cols) ((grid-width / grid-columns) * cols / grid-width) * 100% ! #container margin 0 auto width 100% ! article float left width calculate-column-width(8) ! aside float right width calculate-column-width(4) Functions – Stylus

Slide 75

Slide 75 text

ADVANCED #container { margin: 0 auto; width: 100%; } article { float: left; width: 66.66667%; } aside { float: right; width: 33.33333%; } Functions – Output

Slide 76

Slide 76 text

ADVANCED rgba($color, $alpha) hue($color) saturation($color) lightness($color) adjust-hue($color, $degrees) lighten($color, $amount) darken($color, $amount) saturate($color, $amount) desaturate($color, $amount) grayscale($color) complement($color) invert($color) Color Functions – Sass

Slide 77

Slide 77 text

ADVANCED lighten(@color, amount); darken(@color, amount); saturate(@color, amount); desaturate(@color, amount); fadein(@color, amount); fadeout(@color, amount); fade(@color, amount); spin(@color, amount); Color Functions – Less

Slide 78

Slide 78 text

ADVANCED rgba(color, alpha) lighten(color, amount) darken(color, amount) desaturate(color, amount) saturate(color, amount) invert(color) hue(color) saturation(color) lightness(color) Color Functions – Stylus

Slide 79

Slide 79 text

ADVANCED @if @else if @else @then @for @each @while Control Directives – Sass

Slide 80

Slide 80 text

ADVANCED when Control Directives – Less

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

ADVANCED if else if else unless for Control Directives – Stylus

Slide 83

Slide 83 text

ADVANCED @mixin buttons($color, $type) { @if $type == "flat" { background-color: $color; } @else if $type == "gradient" { background: linear-gradient($color, darken($color, 20%)); } @else if $type == "glossy" { background: linear-gradient($color 50%,darken($color, 20%) 50%); } @else { background-color: $color; } } .button { @include buttons(green, glossy); } if, else – Sass

Slide 84

Slide 84 text

ADVANCED .buttons (@color, @type) when (@type == "flat") { background-color: @color; } .buttons (@color, @type) when (@type == "gradient") { background: linear-gradient(@color, darken(@color, 20%)); } .buttons (@color, @type) when (@type == "glossy") { background: linear-gradient(@color 50%, darken(@color, 20%) 50%); } ! .button { .buttons(green, glossy); } when (if, else) – Less

Slide 85

Slide 85 text

ADVANCED buttons(color, type) if type == "flat" background-color color else if type == "gradient" background linear-gradient(color, darken(color, 20%)) else if type == "glossy" background linear-gradient(color 50%,darken(color, 20%) 50%) else background-color color ! .button buttons(green, glossy) if, else – Stylus

Slide 86

Slide 86 text

ADVANCED .button { background: linear-gradient(#008000 50%, #001a00 50%); } if, else – Output

Slide 87

Slide 87 text

ADVANCED @for $i from 1px to 5px { .border-#{$i} { border: $i solid #000; } } for loop – Sass

Slide 88

Slide 88 text

ADVANCED .border-1px { border: 1px solid black; } .border-2px { border: 2px solid black; } .border-3px { border: 3px solid black; } .border-4px { border: 4px solid black; } for loop – Output

Slide 89

Slide 89 text

ADVANCED $emotions: happy sad excited mustached; ! @each $emotion in $emotions { .feeling-#{$emotion} { background-image: url("images/feeling-#{$emotion}"); } } each loop – Sass

Slide 90

Slide 90 text

ADVANCED .feeling-happy { background-image: url("images/feeling-happy"); } .feeling-sad { background-image: url("images/feeling-sad"); } .feeling-excited { background-image: url("images/feeling-excited"); } .feeling-mustached { background-image: url("images/feeling-mustached"); } each loop – Output

Slide 91

Slide 91 text

ADVANCED $small-breakpoint: 480px; $medium-breakpoint: 768px; $large-breakpoint: 1024px; ! aside { width: 100%; @media screen and (min-width: $small-breakpoint) { width: 100px; float: right; } @media screen and (min-width: $medium-breakpoint) { width: 200px; } @media screen and (min-width: $large-breakpoint) { width: 400px; } } Media Queries – Sass

Slide 92

Slide 92 text

ADVANCED @small-breakpoint: 480px; @medium-breakpoint: 768px; @large-breakpoint: 1024px; ! aside { width: 100%; @media screen and (min-width: @small-breakpoint) { width: 100px; float: right; } @media screen and (min-width: @medium-breakpoint) { width: 200px; } @media screen and (min-width: @large-breakpoint) { width: 400px; } } Media Queries – Less

Slide 93

Slide 93 text

ADVANCED small-breakpoint 480px medium-breakpoint 768px large-breakpoint 1024px ! aside width 100% ! @media screen and (min-width small-breakpoint) width 100px float right ! @media screen and (min-width medium-breakpoint) width 200px @media screen and (min-width large-breakpoint) width 400px Media Queries – Stylus

Slide 94

Slide 94 text

ADVANCED aside { width: 100%; } @media screen and (min-width: 480px) { aside { width: 100px; float: right; } } @media screen and (min-width: 768px) { aside { width: 200px; } } @media screen and (min-width: 1024px) { aside { width: 400px; } } Media Queries – Output

Slide 95

Slide 95 text

ADVANCED @mixin respond-to($name){ @if $name == small-screen { @media only screen and (min-width: 320px) { @content } } @if $name == large-screen { @media only screen and (min-width: 960px) { @content } } } aside { width: 25% @include respond-to(small-screen) { width: 100%; } } @content – Sass

Slide 96

Slide 96 text

ADVANCED aside { width: 25% } ! @media only screen and (min-width: 320px) { aside { width: 100% } } @content – Output

Slide 97

Slide 97 text

ADVANCED $icons: ( home: e601, about: e602, services: e603 ); ! @each $icon-name, $icon-keycode in $icons { .icon-#{$icon-name} { &:before { content: "#{$icon-keycode}"; } } } Hash Maps – Sass

Slide 98

Slide 98 text

ADVANCED icons = { home: e601, about: e602, services: e603 } ! for icon-name, icon-keycode in icons { .icon-{icon-name} { &:before { content: “\{icon-keycode}"; } } } Hash Maps – Stylus

Slide 99

Slide 99 text

ADVANCED .icon-home:before { content: “\e601"; } .icon-about:before { content: “\e602"; } .icon-services:before { content: “\e603"; } Hash Maps – Output

Slide 100

Slide 100 text

FRAMEWORKS

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

No content

Slide 104

Slide 104 text

No content

Slide 105

Slide 105 text

No content

Slide 106

Slide 106 text

No content

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

fin.