Slide 1

Slide 1 text

Why CSS Preprocessors Matter Jina Bolton // Product Designer // Do ConvergeFL // 2012

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

A fractured process makes for a fractured user experience.” ” —Nate Fortin

Slide 4

Slide 4 text

Create pages

Slide 5

Slide 5 text

Create pages

Slide 6

Slide 6 text

Create systems

Slide 7

Slide 7 text

It used to be that designers made an object and walked away. Today the emphasis must shift to designing the entire life cycle.” ” —Paul Sa o

Slide 8

Slide 8 text

CSS Preprocessors

Slide 9

Slide 9 text

Language ! Compilation ! CSS

Slide 10

Slide 10 text

DRY Development

Slide 11

Slide 11 text

Patterns & Proportions

Slide 12

Slide 12 text

Easier maintainability

Slide 13

Slide 13 text

Stylus

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

sass-lang.com

Slide 16

Slide 16 text

compass-style.org

Slide 17

Slide 17 text

Should I choose Sass or SCSS?

Slide 18

Slide 18 text

SCSS Write normal CSS, then add on the extra features. Want to write code like CSS?

Slide 19

Slide 19 text

@mixin sidebar { background: #eee; @include message; }

Slide 20

Slide 20 text

Sass No curly braces, no semi colons, indented, whitespace-sensitive Want to write minimal code?

Slide 21

Slide 21 text

=sidebar background: #eee +message

Slide 22

Slide 22 text

Sass, not SASS!

Slide 23

Slide 23 text

Common Misconceptions

Slide 24

Slide 24 text

I don’t know how to use the command line.” ” You don’t have to.

Slide 25

Slide 25 text

I don’t want to learn Ruby.” ” You don’t have to.

Slide 26

Slide 26 text

livereload.com

Slide 27

Slide 27 text

codekit.com

Slide 28

Slide 28 text

compass.handlino.com

Slide 29

Slide 29 text

mhs.github.com/scout-app

Slide 30

Slide 30 text

I want my CSS file to be formatted pretty.” ” You should be compressing anyway.

Slide 31

Slide 31 text

I’ll have to learn a whole new syntax.” ” Not necessarily.

Slide 32

Slide 32 text

The person I hire may not know it.” ” Then hire someone else who does.

Slide 33

Slide 33 text

Isn’t @import bad?” ” Sass imports are good.

Slide 34

Slide 34 text

/* Main.css */ @import "typography.css"; @import "grid.css"; /* ...more css... */ CSS: 3 files Sass: 1 file

Slide 35

Slide 35 text

Sass Benefits

Slide 36

Slide 36 text

Nesting

Slide 37

Slide 37 text

SCSS: Output: ul.items a { ... } ul.items:hover { ... } .ie-6 ul.items a { ... } ul.items a { ... &:hover { ... } .ie-6 & { ... } }

Slide 38

Slide 38 text

SCSS: Output: ul.items { ... } @media print { ul.items { ... } } ul.items a { ... @media print { ... } }

Slide 39

Slide 39 text

SCSS: Output: .sidebar { border: 1px solid #eee; border-top-color: #fff; border-left: 0; } .sidebar { border: 1px solid #eee { top-color: #fff; left: 0; } }

Slide 40

Slide 40 text

Variables

Slide 41

Slide 41 text

SCSS: Output: body { color: #444; } footer { background: #444; } $text: #444; $bg: $text; body { color: $text; } footer { background: $bg; }

Slide 42

Slide 42 text

Mixins & Extend

Slide 43

Slide 43 text

SCSS: Output: .module { padding: 1em; } .info { padding: 2em } @mixin spacing($s: 1em) { padding: $s; } .module { @include spacing; } .info { @include spacing(2em); }

Slide 44

Slide 44 text

SCSS: Output: .message, .error { ... } .message.alert, .error.alert { ... } .error { ... } .message { ... &.alert { ... } } .error { ... @extend .message; }

Slide 45

Slide 45 text

Placeholder Selectors

Slide 46

Slide 46 text

SCSS: Output: .module, .sidebar { color: #444; } .sidebar, .main { width: 240px; } .module { color: #444; } %grid-1 { width: 240px; } .sidebar { @extend .module; @extend %grid-1; } .main { @extend %grid-1; }

Slide 47

Slide 47 text

Color Functions

Slide 48

Slide 48 text

$text: #444 color: lighten($text, 5%); color: darken($text, 5%); color: saturate($text, 5%); color: adjust-hue($text, 180); color: grayscale($text); color: mix($text, #fff);

Slide 49

Slide 49 text

sassme.arc90.com/

Slide 50

Slide 50 text

Commenting Options

Slide 51

Slide 51 text

SCSS: Output: /* Multiline comment; appears in output */ /* Multiline comment; appears in output */ // Singleline comment; // Hidden from output

Slide 52

Slide 52 text

Operations

Slide 53

Slide 53 text

SCSS: Output: body { font-size: 24px; } $size: 12px; body { font-size: $size * 2; }

Slide 54

Slide 54 text

Functions

Slide 55

Slide 55 text

SCSS: Output: .i-red { background: url(red.png); } .i-blue { background: url(blue.png); } @each $c in red, blue { .i-#{$c} { background: url(#{$c}.png); } }

Slide 56

Slide 56 text

SCSS: Output: .i-red { color: red; } .i-blue { color: blue; } @mixin i($color) { @if $color == red { color: red; } @else { color: blue; } } .i-red { @include i(red); } .i-blue { @include i; }

Slide 57

Slide 57 text

Error Reporting

Slide 58

Slide 58 text

CSS Preprocessors +Style Guides = Super Rad

Slide 59

Slide 59 text

alistapart.com/articles/writingainterfacestyleguide

Slide 60

Slide 60 text

Keep documentation current & useful.

Slide 61

Slide 61 text

engineyard.com/blog/2011/front-end-maintainability-with-sass-and-style-guides

Slide 62

Slide 62 text

First variables. Then mixins. Then placeholder selectors. Then advanced stuff! Start with Baby Steps

Slide 63

Slide 63 text

Sketch it out skitch.com/joesak/di74r/img-028

Slide 64

Slide 64 text

Stay organized

Slide 65

Slide 65 text

Clarity is beautiful.

Slide 66

Slide 66 text

Clarity > Brevity

Slide 67

Slide 67 text

File Organization images/ content/ layout/ javascripts/ vendor/ stylesheets/ vendor/

Slide 68

Slide 68 text

Stay organized

Slide 69

Slide 69 text

If you’re nesting more than 3 levels deep, you’re probably doing something wrong.

Slide 70

Slide 70 text

Engine Yard App Cloud, Early 2011

Slide 71

Slide 71 text

Engine Yard App Cloud, Early 2011

Slide 72

Slide 72 text

jacobrask.github.com/styledocco/

Slide 73

Slide 73 text

jacobrask.github.com/styledocco/styledocco/examples/bootstrap/docs/buttons.html

Slide 74

Slide 74 text

do.com

Slide 75

Slide 75 text

Caption and/or URL

Slide 76

Slide 76 text

// ========================================= // DO WEBSITE // ----------------------------------------- // 01. VENDOR FRAMEWORKS @import "compass" @import "compass/css/pie"

Slide 77

Slide 77 text

// ---------------------------------- // 02. RESET * +box-sizing(border-box) @import "vendor/normalize"

Slide 78

Slide 78 text

// ---------------------------------------------- // 03. DEPENDENCIES // Variables/mixins/placeholders/etc // These don’t emit CSS on their own @import "dependencies/colour" @import "dependencies/measurements" @import "dependencies/typography" @import "dependencies/layout"

Slide 79

Slide 79 text

// ---------------------------------- // 04. FOUNDATION // Plain semantic HTML // No classes/IDs are introduced yet. @import "foundation"

Slide 80

Slide 80 text

// ---------------------------------- // 05. LAYOUT @import "grid" @import "helpers"

Slide 81

Slide 81 text

$breakpoint-iPhone: 20em =respond-to($media) @if $media == iPhone @media #{$breakpoint-iPhone} @content @else if ...

Slide 82

Slide 82 text

@for $i from 1 through $column-count +respond-to(iPhone) %grid-#{$i}-iPhone // ... +respond-to(iPhone) .sidebar @extend %grid-3-iPhone

Slide 83

Slide 83 text

// ------------------------------------- // 06. COMPONENTS // Reusable modules, components, etc. @import "components/forms" @import "components/buttons" @import "components/messaging" @import "components/pop-stripe"

Slide 84

Slide 84 text

// POP STRIPE: https://gist.github.com/3141010 // Thanks goes to Eric A. Meyer // - $position: the starting position or angle of the gradient. // - $colors: a list of all the colors to be used. @function pop-stripe($position, $colors) $colors: if(type-of($colors) != 'list', compact($colors), $colors) $gradient: compact() $width: 100% / length($colors) @for $i from 1 through length($colors) $pop: nth($colors, $i) $new: $pop ($width * ($i - 1)), $pop ($width * $i) $gradient: join($gradient, $new, comma) @return linear-gradient($position, $gradient) .pop-stripe +background-image(pop-stripe(left, ($stripe-colors)))

Slide 85

Slide 85 text

do.com

Slide 86

Slide 86 text

// ---------------------------------- // 07. THEMES @import "themes/light" @import "themes/dark" @import "themes/orangina"

Slide 87

Slide 87 text

// ---------------------------------- // 08. REGIONS @import "regions/header" @import "regions/sidebar" @import "regions/footer"

Slide 88

Slide 88 text

// ---------------------------------- // 09. PRINT @import "print"

Slide 89

Slide 89 text

// ---------------------------------- // 10. TOOLS <% if Rails.env.development? %> @import "show-grid" <% end %>

Slide 90

Slide 90 text

Web standards implementations of nesting, variables, and other preprocessor-related features are being worked into CSS as we speak. CSS Preprocessors are making CSS better.

Slide 91

Slide 91 text

What else?

Slide 92

Slide 92 text

smacss.com

Slide 93

Slide 93 text

stuffandnonsense.co.uk/projects/320andup

Slide 94

Slide 94 text

susy.oddbird.net

Slide 95

Slide 95 text

github.com/thomas-mcdonald/bootstrap-sass

Slide 96

Slide 96 text

blesscss.com

Slide 97

Slide 97 text

Just give it a try!

Slide 98

Slide 98 text

sass-lang.com

Slide 99

Slide 99 text

Team Sass Design FTW!

Slide 100

Slide 100 text

@TeamSassDesign

Slide 101

Slide 101 text

#teamSass

Slide 102

Slide 102 text

Be regular and orderly in your life so that you may be violent and original in your work.” ” —Gustave Flaubert

Slide 103

Slide 103 text

sushiandrobots.com

Slide 104

Slide 104 text

artinmyco ee.com

Slide 105

Slide 105 text

speakerdeck.com/u/jina

Slide 106

Slide 106 text

@jina Thank You!