Slide 1

Slide 1 text

... The Excruciating Kitchen Sink Analogy ... OOCSS, SMACSS, and BEM ... “Allow markup to change” ... “Keep your selectors short” ... “Don’t sweat the class names” ... “Be pragmatic” ... “Extend your modules” ... “Layout modules” ... Style Guides ... Homework/Beer Creating maintainable CSS

Slide 2

Slide 2 text

Rich Archer ...@slocombe [email protected]

Slide 3

Slide 3 text

Creating a new site is sexy

Slide 4

Slide 4 text

Maintaining a site is painful

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

• SMACSS smacss.com • OOCSS oocss.org • BEM bem.info A better way to structure our styles?

Slide 7

Slide 7 text

Whatever; CSS is easy! ...no namespaces ...no macros ...no mixins ...no functions ...no variables

Slide 8

Slide 8 text

CSS makes it easy for us to be stupid

Slide 9

Slide 9 text

CSS makes it easy for us to be stupid #content.box { ... } #wrapper #content.box { ... } #i-mean-it-this-time #wrapper #content.box { ... }

Slide 10

Slide 10 text

• LESS lesscss.org • SASS/SCSS sass-lang.com • Stylus learnboost.github.com/stylus But we have preprocessors!

Slide 11

Slide 11 text

But we have preprocessors! #i-mean-it-this-time { #wrapper { #content.box { ... } } }

Slide 12

Slide 12 text

• SMACSS smacss.com • OOCSS oocss.org • BEM bem.info Seeking to address di!erent problems

Slide 13

Slide 13 text

“Separate Content from Presentation” The One Rule

Slide 14

Slide 14 text

Sites are always adapting Allow for markup to change

Slide 15

Slide 15 text

http://vimeo.com/29088090 37 Signals

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Keep your selectors short

Slide 18

Slide 18 text

html #content #wrapper article.main-article:nth-child(2) div.panel { ... }

Slide 19

Slide 19 text

p.panel, div.panel { ... } .panel { ... }

Slide 20

Slide 20 text

Keep your selectors short ...easier debugging ...easier point of entry ...avoid speci!city issues ...CSS evaluates right-to-left ...performance?

Slide 21

Slide 21 text

Headings Headings Headings Headings Headings Examples!

Slide 22

Slide 22 text

h1 a h2 h2 h2 h4 h3 h4

Slide 23

Slide 23 text

h1 { font-size: 36px; } h2 { font-size: 24px; } #sidebar li a, h3 { font-size: 18px; }

Slide 24

Slide 24 text

.heading-headline { font-size: 36px; } .heading-subheadline { font-size: 24px; } .heading-byline { font-size: 18px; } Modules

Slide 25

Slide 25 text

.heading-headline { font-size: 36px; } .heading-subheadline { font-size: 24px; } .heading-byline { font-size: 18px; } .theme-summer { color: gold; } .theme-autumn { color: burlywood; } .theme-winter { color: blue; } Combinations of modules

Slide 26

Slide 26 text

(Google doesn’t care) Don’t sweat the class names

Slide 27

Slide 27 text

.heading-headline { font-size: 36px; } .heading-subheadline { font-size: 24px; } .heading-byline { font-size: 18px; }

Slide 28

Slide 28 text

.h-headline { font-size: 36px; } .h-subheadline { font-size: 24px; } .h-byline { font-size: 18px; }

Slide 29

Slide 29 text

.bob--hugetext { font-size: 36px; } .bob--middletext{ font-size: 24px; } .bob--teenytext{ font-size: 18px; }

Slide 30

Slide 30 text

  • ...
ul li {} ... .search-result-item {}

Slide 31

Slide 31 text

  • ...
  • ...
  • ...
  • ...
  • ...

Slide 32

Slide 32 text

...

Slide 33

Slide 33 text

...
...
...
...

Slide 34

Slide 34 text

.fancy-link { height: 20px; background: red; } button.fancy-link { padding: 0; border: 0; } Be pragmatic

Slide 35

Slide 35 text

Performance boost? ...reuse of code ...smaller CSS !les ...faster download ...less to parse ...combine modules for free varieties

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Title

...
.messagebox { border: 1px solid green; } .messagebox h2 { color: red; }

Slide 39

Slide 39 text

Title

Another title

...
.messagebox { border: 1px solid green; } .messagebox h2 { color: red; }

Slide 40

Slide 40 text

Title

Another title

...
.messagebox { border: 1px solid green; } .messagebox-header { color: red; }

Slide 41

Slide 41 text

Extend your modules

Slide 42

Slide 42 text

.messagebox { border: 1px solid black; color: white; background: green; }

Slide 43

Slide 43 text

.messagebox { border: 1px solid black; color: white; background: green; } .mildalert { border: 1px solid black; color: white; background: orange; } .badalert { border: 1px solid black; color: white; background: red; }

Slide 44

Slide 44 text

.messagebox { border: 3px solid black; color: white; background: green; } .messagebox-mild { background: orange; } .messagebox-bad { background: red; }

Slide 45

Slide 45 text

Easier organisation ...Easier to !nd relevant code ...Less “where should this rule go?” ...More predictable ...More maintainable ...Easier debugging ...Faster development

Slide 46

Slide 46 text

Layout modules

Slide 47

Slide 47 text

Layout Handles positioning only. Twitter Bootstrap sca!olding, OOCSS, 960gs

Slide 48

Slide 48 text

.btn .btn .content .subcontent .footer .btn

Slide 49

Slide 49 text

.btn .span3 .btn .span3 .content .span8 .subcontent .span4 .footer .btn .row .span6

Slide 50

Slide 50 text

Layout Handles positioning only. Twitter Bootstrap sca!olding, OOCSS, 960gs

Slide 51

Slide 51 text

Module Layout Handles positioning only. Twitter Bootstrap sca!olding, OOCSS, 960gs .button, .messageBox, .search-item

Slide 52

Slide 52 text

Module Layout Handles positioning only. Twitter Bootstrap sca!olding, OOCSS, 960gs Base Browser resets, basic typography, element styles .button, .messageBox, .search-item

Slide 53

Slide 53 text

Style guides

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

Site-speci"c style guides ...a CSS component example page ...uses live CSS ...acts as crib sheets for newbies ...single page to check for modi!cations

Slide 57

Slide 57 text

Useful links Rich Archer @slocombe [email protected] • SMACSS smacss.com • OOCSS oocss.org • BEM bem.info • Twitter Bootstrap getbootstrap.com • Jonathan Snook @snookca • Nicolle Sullivan @stubbornella