Slide 1

Slide 1 text

Sass Nathan Henderson Refresh Rochester – 6/25/2013

Slide 2

Slide 2 text

CSS & pre-processors

Slide 3

Slide 3 text

Syntactically Awesome Stylesheets

Slide 4

Slide 4 text

Syntactically Awesome Stylesheets

Slide 5

Slide 5 text

http://sass-lang.com

Slide 6

Slide 6 text

Sass Basics

Slide 7

Slide 7 text

body { font-family: sans-serif; font-size: 30em; font-weight: bold; } #contents { width: 800px; } #contents #sidebar { float: right; width: 200px; } #contents #main { width: 600px; background: #eeeeee; } #contents #main h2 { color: blue; } #footer { height: 200px; } CSS body { font-family: sans-serif; font-size: 30em; font-weight: bold; } #contents { width: 800px; } #contents #sidebar { float: right; width: 200px; } #contents #main { width: 600px; background: #eeeeee; } #contents #main h2 { color: blue; } #footer { height: 200px; } Nested CSS

Slide 8

Slide 8 text

body { font-family: sans-serif; font-size: 30em; font-weight: bold; } #contents { width: 800px; #sidebar { float: right; width: 200px; } #main { width: 600px; background: #eeeeee; h2 { color: blue; } } } #footer { height: 200px; } SCSS body { font-family: sans-serif; font-size: 30em; font-weight: bold; } #contents { width: 800px; } #contents #sidebar { float: right; width: 200px; } #contents #main { width: 600px; background: #eeeeee; } #contents #main h2 { color: blue; } #footer { height: 200px; } Nested CSS

Slide 9

Slide 9 text

body { font-family: sans-serif; font-size: 30em; font-weight: bold; } #contents { width: 800px; #sidebar { float: right; width: 200px; } #main { width: 600px; background: #eeeeee; h2 { color: blue; } } } #footer { height: 200px; } SCSS body { font-family: sans-serif; font-size: 30em; font-weight: bold; } #contents { width: 800px; } #contents #sidebar { float: right; width: 200px; } #contents #main { width: 600px; background: #eeeeee; } #contents #main h2 { color: blue; } #footer { height: 200px; } Nested CSS

Slide 10

Slide 10 text

body { font-family: sans-serif; font-size: 30em; font-weight: bold; } #contents { width: 800px; #sidebar { float: right; width: 200px; } #main { width: 600px; background: #eeeeee; h2 { color: blue; } } } #footer { height: 200px; } SCSS • SCSS = “Sassy CSS” • Default Sass syntax • Superset of CSS3 (CSS is SCSS!) • Nested selectors

Slide 11

Slide 11 text

body { font-family: sans-serif; font-size: 30em; font-weight: bold; } #contents { width: 800px; #sidebar { float: right; width: 200px; } #main { width: 600px; background: #eeeeee; h2 { color: blue; } } } #footer { height: 200px; } SCSS • SCSS = “Sassy CSS” • Default Sass syntax • Superset of CSS3 (CSS is SCSS!) • Nested selectors • Nested properties too

Slide 12

Slide 12 text

• SCSS = “Sassy CSS” • Default Sass syntax • Superset of CSS3 (CSS is SCSS!) • Nested selectors • Nested properties too body { font: { family: sans-serif; size: 30em; weight: bold; } } #contents { width: 800px; #sidebar { float: right; width: 200px; } #main { width: 600px; background: #eeeeee; h2 { color: blue; } } } #footer { height: 200px; } SCSS

Slide 13

Slide 13 text

• SCSS = “Sassy CSS” • Default Sass syntax • Superset of CSS3 (CSS is SCSS!) • Nested selectors • Nested properties too • Indentation isn’t required, but… body { font: { family: sans-serif; size: 30em; weight: bold; } } #contents { width: 800px; #sidebar { float: right; width: 200px; } #main { width: 600px; background: #eeeeee; h2 { color: blue; } } } #footer { height: 200px; } SCSS

Slide 14

Slide 14 text

body { font-family: sans-serif; font-size: 30em; font-weight: bold; } #contents { width: 800px; #sidebar { float: right; width: 200px; } #main { width: 600px; background: #eeeeee; h2 { color: blue; } } } #footer { height: 200px; } SCSS body font-family: sans-serif font-size: 30em font-weight: bold #contents width: 800px #sidebar float: right width: 200px #main width: 600px background: #eeeeee h2 color: blue #footer height: 200px Sass

Slide 15

Slide 15 text

body { font-family: sans-serif; font-size: 30em; font-weight: bold; } #contents { width: 800px; #sidebar { float: right; width: 200px; } #main { width: 600px; background: #eeeeee; h2 { color: blue; } } } #footer { height: 200px; } SCSS body font-family: sans-serif font-size: 30em font-weight: bold #contents width: 800px #sidebar float: right width: 200px #main width: 600px background: #eeeeee h2 color: blue #footer height: 200px Sass

Slide 16

Slide 16 text

• “Sass” or “indented” syntax • White space aware (2 space soft tabs are your friends) • Completely optional (I know, it’s not for everybody) body font-family: sans-serif font-size: 30em font-weight: bold #contents width: 800px #sidebar float: right width: 200px #main width: 600px background: #eeeeee h2 color: blue #footer height: 200px Sass

Slide 17

Slide 17 text

The Good Stuff

Slide 18

Slide 18 text

The Good Stuff ✦ Variables

Slide 19

Slide 19 text

Variables body font-family: sans-serif font-size: 30em font-weight: bold #contents width: 800px #sidebar float: right width: 200px #main width: 600px background: #eeeeee h2 color: blue #footer height: 200px // Variable Definitions $page-width: 800px $sidebar-width: 200px $primary-color: #eeeeee

Slide 20

Slide 20 text

Variables body font-family: sans-serif font-size: 30em font-weight: bold #contents width: 800px #sidebar float: right width: 200px #main width: 600px background: #eeeeee h2 color: blue #footer height: 200px // Variable Definitions $page-width: 800px $sidebar-width: 200px $primary-color: #eeeeee body font-family: sans-serif font-size: 30em font-weight: bold #contents width: $page-width #sidebar float: right width: $sidebar-width #main width: ??? background: $primary-color h2 color: blue #footer height: 200px

Slide 21

Slide 21 text

Variables body font-family: sans-serif font-size: 30em font-weight: bold #contents width: 800px #sidebar float: right width: 200px #main width: 600px background: #eeeeee h2 color: blue #footer height: 200px // Variable Definitions $page-width: 800px $sidebar-width: 200px $primary-color: #eeeeee body font-family: sans-serif font-size: 30em font-weight: bold #contents width: $page-width #sidebar float: right width: $sidebar-width #main width: ??? background: $primary-color h2 color: blue #footer height: 200px

Slide 22

Slide 22 text

Variables body font-family: sans-serif font-size: 30em font-weight: bold #contents width: 800px #sidebar float: right width: 200px #main width: 600px background: #eeeeee h2 color: blue #footer height: 200px // Variable Definitions $page-width: 800px $sidebar-width: 200px $primary-color: #eeeeee body font-family: sans-serif font-size: 30em font-weight: bold #contents width: $page-width #sidebar float: right width: $sidebar-width #main width: ??? background: $primary-color h2 color: blue #footer height: 200px body font-family: sans-serif font-size: 30em font-weight: bold #contents width: $page-width #sidebar float: right width: $sidebar-width #main width: $page-width - $sidebar-width background: $primary-color h2 color: blue #footer height: 200px

Slide 23

Slide 23 text

Variables body font-family: sans-serif font-size: 30em font-weight: bold #contents width: 800px #sidebar float: right width: 200px #main width: 600px background: #eeeeee h2 color: blue #footer height: 200px // Variable Definitions $page-width: 800px $sidebar-width: 200px $primary-color: #eeeeee body font-family: sans-serif font-size: 30em font-weight: bold #contents width: $page-width #sidebar float: right width: $sidebar-width #main width: ??? background: $primary-color h2 color: blue #footer height: 200px body font-family: sans-serif font-size: 30em font-weight: bold #contents width: $page-width #sidebar float: right width: $sidebar-width #main width: $page-width - $sidebar-width background: $primary-color h2 color: blue #footer height: 200px MATH

Slide 24

Slide 24 text

Real World Example

Slide 25

Slide 25 text

Real World Example // Dimensions $page_width: 960px $nav_tabs: 6 // number of navigation tabs $tab_width: round($page_width / $nav_tabs) - 1

Slide 26

Slide 26 text

Real World Example // Dimensions $page_width: 960px $nav_tabs: 7 // number of navigation tabs $tab_width: round($page_width / $nav_tabs) - 1

Slide 27

Slide 27 text

Real World Example // Dimensions $page_width: 960px $nav_tabs: 7 // number of navigation tabs $tab_width: round($page_width / $nav_tabs) - 1

Slide 28

Slide 28 text

Using Variables ✦ Colors ✦ Font Stacks ✦ Margins & Padding ✦ Border widths ✦ Border radii

Slide 29

Slide 29 text

The Good Stuff ✦ Variables ✦ Mixins

Slide 30

Slide 30 text

Mixins @mixin large-text font-family: Helvetica, Arial, sans-serif font-size: 20px font-weight: bold color: #ff0000

Slide 31

Slide 31 text

Mixins @mixin large-text font-family: Helvetica, Arial, sans-serif font-size: 20px font-weight: bold color: #ff0000 #content h1 @include large-text

Slide 32

Slide 32 text

More Mixins @mixin ez-border($width, $color) border-width: $width border-style: solid border-color: $color

Slide 33

Slide 33 text

More Mixins @mixin ez-border($width, $color) border-width: $width border-style: solid border-color: $color #aboutbox @include ez-border(2px, #eee)

Slide 34

Slide 34 text

More Mixins @mixin ez-border($width, $color) border-width: $width border-style: solid border-color: $color #aboutbox @include ez-border(2px, #eee) @mixin ez-border($width: 2px, $color: #eee) border-width: $width border-style: solid border-color: $color #aboutbox @include ez-border

Slide 35

Slide 35 text

More Mixins @mixin ez-border($width, $color) border-width: $width border-style: solid border-color: $color #aboutbox @include ez-border(2px, #eee) @mixin ez-border($width: 2px, $color: #eee) border-width: $width border-style: solid border-color: $color #aboutbox @include ez-border #aboutbox @include ez-border(1px, #444)

Slide 36

Slide 36 text

Fun with Mixins ✦ Mixin definitions can include other mixins ✦ Try the ‘&’ parent selector ✦ Global variables in mixins

Slide 37

Slide 37 text

The Good Stuff ✦ Variables ✦ Mixins ✦ Selector Inheritance “@extend”

Slide 38

Slide 38 text

@extend
Oh snap! The roof is on fire!
.alert border: 1px #f00 background-color: #eee .criticalAlert border-width: 3px color: #8a0808

Slide 39

Slide 39 text

@extend
Oh snap! The roof is on fire!
.alert border: 1px #f00 background-color: #eee .criticalAlert border-width: 3px color: #8a0808 .alert border: 1px #f00 background-color: #eee .criticalAlert @extend .alert border-width: 3px color: #8a0808

Slide 40

Slide 40 text

@extend
Oh snap! The roof is on fire!
.alert border: 1px #f00 background-color: #eee .criticalAlert border-width: 3px color: #8a0808
Oh snap! The roof is on fire!
.alert border: 1px #f00 background-color: #eee .criticalAlert @extend .alert border-width: 3px color: #8a0808

Slide 41

Slide 41 text

Multiple @extends .alert border: 1px #f00 background-color: #eee .criticalAlert border-width: 3px color: #8a0808 .greatGooglyMoogly @extend .alert @extend .criticalAlert border-style: dashed
Oh snap! The roof is on fire!

Slide 42

Slide 42 text

Multiple @extends .alert border: 1px #f00 background-color: #eee .criticalAlert border-width: 3px color: #8a0808 .greatGooglyMoogly @extend .alert @extend .criticalAlert border-style: dashed
Oh snap! The roof is on fire!
.alert border: 1px #f00 background-color: #eee .criticalAlert border-width: 3px color: #8a0808 .greatGooglyMoogly @extend .alert, .criticalAlert border-style: dashed

Slide 43

Slide 43 text

@extend vs. Mixins @extend modifies selectors, mixins add properties & values .alert border: 1px #f00 background-color: #eee .criticalAlert @extend .alert border-width: 3px color: #8a0808 Sass Input (@extend) .alert, .criticalAlert border: 1px #f00 background-color: #eee .criticalAlert border-width: 3px color: #8a0808 CSS Output

Slide 44

Slide 44 text

@extend vs. Mixins @extend modifies selectors, mixins add properties & values @mixin alert border: 1px #f00 background-color: #eee .criticalAlert @mixin alert border-width: 3px color: #8a0808 Sass Input (@mixin) .criticalAlert border: 1px #f00 background-color: #eee border-width: 3px color: #8a0808 CSS Output

Slide 45

Slide 45 text

Placeholder selector %-prefixed selectors don’t get rendered to CSS %alert border: 1px #f00 background-color: #eee .criticalAlert @extend %alert border-width: 3px color: #8a0808 Sass Input .criticalAlert border: 1px #f00 background-color: #eee .criticalAlert border-width: 3px color: #8a0808 CSS Output

Slide 46

Slide 46 text

The Good Stuff ✦ Variables ✦ Mixins ✦ Selector Inheritance “@extend” ✦ Other goodies

Slide 47

Slide 47 text

Parent Selector a font-weight: bold text-decoration: none a:hover text-decoration: underline

Slide 48

Slide 48 text

Parent Selector a font-weight: bold text-decoration: none a:hover text-decoration: underline a font-weight: bold text-decoration: none &:hover text-decoration: underline

Slide 49

Slide 49 text

@import & Partials @import "rounded-corners", "text-shadow" filenames that start with an underscore won’t be compiled into the output directory _rounded-corners.sass _text-shadow.sass

Slide 50

Slide 50 text

Installing and Using Sass

Slide 51

Slide 51 text

Installing and Using Sass Command Line

Slide 52

Slide 52 text

Installing and Using Sass Command Line GUI Apps

Slide 53

Slide 53 text

Installing and Using Sass Command Line GUI Apps Other frameworks, templates, and project generators

Slide 54

Slide 54 text

Command Line ✦ Requires Ruby ✦ Best to use a new(ish) version of Ruby (1.9.3 or higher) ✦ Probably a good idea to use a Ruby version manager (RVM, rbenv, etc.)

Slide 55

Slide 55 text

Installing Sass gem install sass

Slide 56

Slide 56 text

Using Sass sass input.sass output.css

Slide 57

Slide 57 text

Using Sass sass input.sass output.css sass --watch input.sass:output.css

Slide 58

Slide 58 text

Using Sass sass input.sass output.css sass --watch input.sass:output.css sass --watch app/sass:public/stylesheets

Slide 59

Slide 59 text

GUI Apps ✦ CodeKit Mac http://incident57.com/codekit/ ✦ Scout Mac & Windows http://mhs.github.io/scout-app/ ✦ Compass.app Mac, Windows, and Linux http://compass.handlino.com ✦ Others

Slide 60

Slide 60 text

Other frameworks, templates, and project generators ✦ Yeoman http://yeoman.io ✦ Middleman http://middlemanapp.com

Slide 61

Slide 61 text

Also built into… codepen.io

Slide 62

Slide 62 text

More Awesome Stuff

Slide 63

Slide 63 text

http://compass-style.org

Slide 64

Slide 64 text

http://susy.oddbird.net

Slide 65

Slide 65 text

Around the Interwebs Demo time!

Slide 66

Slide 66 text

Q&A

Slide 67

Slide 67 text

Convinced?

Slide 68

Slide 68 text