Slide 1

Slide 1 text

Writing maintainable CSS with Sass

Slide 2

Slide 2 text

@polarblau

Slide 3

Slide 3 text

( https://github.com/polarblau/maintainable-stylesheets/ )

Slide 4

Slide 4 text

Alltag (Everyday life)

Slide 5

Slide 5 text

Technical debt Confidence LOC

Slide 6

Slide 6 text

Alltag & Stylesheets

Slide 7

Slide 7 text

Technical debt Confidence LOC

Slide 8

Slide 8 text

Why? What makes the work with stylesheets painful?

Slide 9

Slide 9 text

It’s too easy!

Slide 10

Slide 10 text

It’s easy to learn, everybody can do it!

Slide 11

Slide 11 text

It’s easy to read, but hard to comprehend.

Slide 12

Slide 12 text

It’s easy to start, but hard to scale.

Slide 13

Slide 13 text

Let’s get serious!

Slide 14

Slide 14 text

programming == serious_business css == programming

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

New Legacy

Slide 17

Slide 17 text

New project

Slide 18

Slide 18 text

Define all rules!

Slide 19

Slide 19 text

Distribute all the rules!

Slide 20

Slide 20 text

Enforce all the rules!

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Rules:

Slide 23

Slide 23 text

Version control

Slide 24

Slide 24 text

What would do?

Slide 25

Slide 25 text

HTML

Slide 26

Slide 26 text

Stay clear of frameworks

Slide 27

Slide 27 text

Keep styles where they belong

Slide 28

Slide 28 text

Files

Slide 29

Slide 29 text

Composition / Color / Type Elements of a visual language

Slide 30

Slide 30 text

/layout /colors /typography

Slide 31

Slide 31 text

/layout /colors /typography /helpers /base (reset, etc.) /ie /print

Slide 32

Slide 32 text

Slide 33

Slide 33 text

Media queries?

Slide 34

Slide 34 text

=respond-to($media) @if $media == desktop @media screen and (min-width: 1280px) @content @else if $media == large-screen @media screen and (min-width: 1400px) @content

Slide 35

Slide 35 text

h1 font-size: 2em +respond-to(desktop) h1 font-size: 3em

Slide 36

Slide 36 text

Keep files small and readable

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Nesting for brevity

Slide 39

Slide 39 text

#content h2 strong color: red &.foo font-size: 1.2em

Slide 40

Slide 40 text

Mixins for clarity

Slide 41

Slide 41 text

=custom-serif($weight: normal) font-family: "ff-tisa-web-pro", Georgia, serif @if $weight == bold font-weight: 700 @else font-weight: 300

Slide 42

Slide 42 text

h1 +custom-serif

Slide 43

Slide 43 text

=greyscale +prefixer(filter, grayscale(100%))

Slide 44

Slide 44 text

Plan for re–usability

Slide 45

Slide 45 text

Documentation

Slide 46

Slide 46 text

/* This comment is * several lines long. * since it uses the CSS comment syntax, * it will appear in the CSS output. */ body color: black // These comments are only one line long each. // They won't appear in the CSS output, // since they use the single-line comment syntax. a color: green

Slide 47

Slide 47 text

/* This comment is * several lines long. * since it uses the CSS comment syntax, * it will appear in the CSS output. */ body { color: black; } a { color: green; }

Slide 48

Slide 48 text

// @file colors.sass // // @description Colors definitions as Sass variables. // @authors Florian Plank ([email protected])

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Keep an (up–to–date) style guide

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

http://assets.warpspire.com/images/kss/styleguide-full.png

Slide 53

Slide 53 text

Semantic naming

Slide 54

Slide 54 text

“I’d describe semantics as it relates to HTML as tags, classes, IDs, and attributes describing but not specifying the content they enclose.” —Chris Coyier

Slide 55

Slide 55 text

Foo
Bar
Bat

Slide 56

Slide 56 text

Foo
Bat

Slide 57

Slide 57 text

Decouple styles from mark–up structure?

Slide 58

Slide 58 text

.social li:nth-child(1) { … } .social li:nth-child(2) { … } .social li:nth-child(3) { … }

Slide 59

Slide 59 text

.social .twitter { … } .social .facebook { … } .social .linkedin { … }

Slide 60

Slide 60 text

Validate?

Slide 61

Slide 61 text

Use !important as a debugging tool (thing “console.log()”)

Slide 62

Slide 62 text

Test? (Selenium, JS, …)

Slide 63

Slide 63 text

… nitty gritty details

Slide 64

Slide 64 text

Indentation (flat, tree?) Position of braces Short form or long Class name separators

Slide 65

Slide 65 text

Legacy project

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

Fix readability

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

Remove unused styles

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

Extract variables (Sass)

Slide 73

Slide 73 text

Search and fix obvious duplication

Slide 74

Slide 74 text

—Specificity

Slide 75

Slide 75 text

specificity = a, b, c, d a = inline styles b = ID c = classes/attributes/pseudo–classes d = elements and pseudo–elements

Slide 76

Slide 76 text

h1 = 0, 0, 0, 1

Slide 77

Slide 77 text

#foo h1 = 0, 1, 0, 1

Slide 78

Slide 78 text

#foo #bar h1.bat = 0, 2, 1, 1

Slide 79

Slide 79 text

Fix naming

Slide 80

Slide 80 text

Search and fix obvious duplication

Slide 81

Slide 81 text

Split files

Slide 82

Slide 82 text

Quasi clean slate

Slide 83

Slide 83 text

HELP!

Slide 84

Slide 84 text

http://github/polarblau/perseus

Slide 85

Slide 85 text

Good luck!