Slide 1

Slide 1 text

Avoiding the Threat of Awful CSS

Slide 2

Slide 2 text

Tim G. Thomas @timgthomas

Slide 3

Slide 3 text

Senior Consultant @ Headspring (Work for us!)

Slide 4

Slide 4 text

The Problem: Maintainability

Slide 5

Slide 5 text

The Solution: Patterns!

Slide 6

Slide 6 text

Developers! Developers! Developers! (Are Good at This)

Slide 7

Slide 7 text

More Maintainable

Slide 8

Slide 8 text

More Consistent

Slide 9

Slide 9 text

Fewer Headaches

Slide 10

Slide 10 text

But How?

Slide 11

Slide 11 text

Two Steps

Slide 12

Slide 12 text

Step 1: Layout First

Slide 13

Slide 13 text

This is Easy*

Slide 14

Slide 14 text

*Not Interesting (For This Talk)

Slide 15

Slide 15 text

Step 2: Write Flexible CSS

Slide 16

Slide 16 text

What makes CSS “"exible”?

Slide 17

Slide 17 text

Flexible CSS is Purposeful

Slide 18

Slide 18 text

Purpose: Site Branding

Slide 19

Slide 19 text

Site Branding === “Global Styles”

Slide 20

Slide 20 text

Global Styles use

Slide 21

Slide 21 text

Global Styles button { background: #333; border: 1px solid #000; color: #fff; }

Slide 22

Slide 22 text

Everything Else === “Component Styles”

Slide 23

Slide 23 text

Component Styles use .classes

Slide 24

Slide 24 text

Component Styles .contact-list { line-height: 2.0em; list-style: square; padding: 10px 20px 0; }

Slide 25

Slide 25 text

SMACSS(.com)

Slide 26

Slide 26 text

Global Styles => “Base Styles”

Slide 27

Slide 27 text

Component Styles => “Layouts” and “Modules”

Slide 28

Slide 28 text

Layouts are Big Page Parts

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Layouts in CSS .l-navigation { /* ... */ } .l-hero { /* ... */ } .l-featured { /* ... */ } .l-legal { /* ... */ }

Slide 31

Slide 31 text

Layouts are Unique

Slide 32

Slide 32 text

Modules are Smaller Parts

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Modules in CSS .featured-list { /* ... */ } .featured-list .title { /* ... */ } .featured-list .item { /* ... */ }

Slide 35

Slide 35 text

Modules are Designed for Reuse

Slide 36

Slide 36 text

Modules are Designed for Relocation

Slide 37

Slide 37 text

Flexible Selectors

Slide 38

Slide 38 text

Flexible Selectors are Short

Slide 39

Slide 39 text

Flexible Selectors: Short header > h1 #main .date span > em { /* Yuck. */ } .meaningful { /* Yum! */ }

Slide 40

Slide 40 text

Flexible Selectors use Elements (for Globals)

Slide 41

Slide 41 text

Flexible Selectors: Elements nav { /* ... */ } button { /* ... */ } input { /* ... */ } aside { /* ... */ }

Slide 42

Slide 42 text

Flexible Selectors use Classes (for everything else)

Slide 43

Slide 43 text

Flexible Selectors: Classes .messages { /* ... */ } .contacts { /* ... */ } .tasks { /* ... */ }

Slide 44

Slide 44 text

Flexible Selectors DO NOT use IDs

Slide 45

Slide 45 text

Flexible Selectors: IDs #im-not-flexible { /* :-( */ } .im-flexible { /* :-) */ }

Slide 46

Slide 46 text

Flexible Selectors aren’t Shared with JavaScript

Slide 47

Slide 47 text

Flexible Selectors: JavaScript $(‘.doSomething’).fadeIn(); .lookLikeSomething { /* ... */ }

Slide 48

Slide 48 text

Flexible CSS is Meaningfully Named

Slide 49

Slide 49 text

Meaningful Names: What Stu# Is

Slide 50

Slide 50 text

Meaningful Names: NOT What Stu# Looks Like

Slide 51

Slide 51 text

NOT Meaningfully Named .lp10 { } .red { } .big-font { }

Slide 52

Slide 52 text

Meaningfully Named .emphasized-list { } .featured-products { } button.primary { }

Slide 53

Slide 53 text

Flexible CSS is Logically Grouped

Slide 54

Slide 54 text

Flexible CSS is LOGICALLY Grouped

Slide 55

Slide 55 text

Logical Groups .green-border { /* Boo! Hiss! */ border: 1px solid #0f0; } .user-selected { /* Yay! */ border: 1px solid #f0f; }

Slide 56

Slide 56 text

Logical Groups Have a Single Reason to Change

Slide 57

Slide 57 text

Logical Groups DO Reduce Duplication

Slide 58

Slide 58 text

Logical Groups MAY Contain Duplicate Styles

Slide 59

Slide 59 text

How to Fix Duplication:

Slide 60

Slide 60 text

How to Fix Duplication: Preprocessors!

Slide 61

Slide 61 text

Preprocessors are Transpilers

Slide 62

Slide 62 text

Preprocessors Turn This… .cohesive-group-a { border: 1px solid #f0f; color: #00f; font: 1.2em/2.4em Comic Sans; } .cohesive-group-b { border: 1px solid #f0f; color: #f00; font: 1.2em/2.4em Comic Sans; }

Slide 63

Slide 63 text

…Into This: .shared-styles { border: 1px solid #f0f; font: 1.2em/2.4em Comic Sans; } .cohesive-group-a { .shared-styles(); color: #00f; } .cohesive-group-b { .shared-styles(); color: #f00; }

Slide 64

Slide 64 text

Other Cool Stu#: Vendor Pre$xes! .scale(scale-amount) { -webkit-transform: scale(scale-amount); -moz-transform: scale(scale-amount); -ms-transform: scale(scale-amount); -o-transform: scale(scale-amount); transform: scale(scale-amount); }

Slide 65

Slide 65 text

Other Cool Stu#: Vendor Pre$xes! .foo { .scale(0.8); } .bar { .scale(0.4); }

Slide 66

Slide 66 text

My Favorite: Nesting! .book-list { .cover { .title { } .author { } } }

Slide 67

Slide 67 text

My Favorite: Nesting! .book-list .cover .title { } .book-list .cover .author { }

Slide 68

Slide 68 text

Preprocessors: LESS and SASS

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

To Review

Slide 72

Slide 72 text

Good CSS is Flexible

Slide 73

Slide 73 text

Flexible CSS Means Patterns

Slide 74

Slide 74 text

Flexible CSS Means Separation of Concerns

Slide 75

Slide 75 text

Flexible CSS Is Helped By SMACSS

Slide 76

Slide 76 text

Flexible CSS Is Helped By Preprocessors

Slide 77

Slide 77 text

Above All: Good CSS is Possible!

Slide 78

Slide 78 text

Above All: Good CSS is Easy!

Slide 79

Slide 79 text

Above All: Good CSS is Fun!

Slide 80

Slide 80 text

Thanks for Coming!

Slide 81

Slide 81 text

Rate meh! http://spkr8.com/t/11651