An Introduction to Object Oriented CSS

79
An Introduction to Object Oriented CSS Scalable and Maintainable Stylesheets Nati Devalle - @Taly UX Designer

description

Talk I gave for the Design team at MercadoLibre.

Transcript of An Introduction to Object Oriented CSS

Page 1: An Introduction to Object Oriented CSS

An Introduction to Object Oriented CSSScalable and Maintainable Stylesheets

Nati Devalle - @Taly UX Designer

Page 2: An Introduction to Object Oriented CSS

Starting a project from scratch

Page 3: An Introduction to Object Oriented CSS
Page 4: An Introduction to Object Oriented CSS

6 months later...

Page 5: An Introduction to Object Oriented CSS
Page 6: An Introduction to Object Oriented CSS

WHY?

Page 7: An Introduction to Object Oriented CSS

We keep piling styles up

Page 8: An Introduction to Object Oriented CSS

instead of reusing them

Page 9: An Introduction to Object Oriented CSS

Where do we start?http://www.flickr.com/photos/mrlemming_photos/5750248841/

Page 10: An Introduction to Object Oriented CSS

Object OrientedCSS

by Nicole Sullivan

Page 11: An Introduction to Object Oriented CSS

2 Principles

1. Separation of Structure from Skin

2. Separation of Containers from Content

Page 12: An Introduction to Object Oriented CSS

2 Principles

1. Separation of Structure from Skin

2. Separation of Containers from Content

Page 13: An Introduction to Object Oriented CSS
Page 14: An Introduction to Object Oriented CSS
Page 15: An Introduction to Object Oriented CSS

Structure Skin

Page 16: An Introduction to Object Oriented CSS

Structure Skin

Page 17: An Introduction to Object Oriented CSS

Scalable

.ch-box-error {}

.ch-box-attention {}

Page 18: An Introduction to Object Oriented CSS

Scalable

.ch-box-error {}

.ch-box-attention {}

.ch-box-help {}

.ch-box-information {}

.ch-box-ok {}

Page 19: An Introduction to Object Oriented CSS

Maintainable

[class*='ch-box'] {border-radius: 5px;padding: 10px;margin: 0 0 10px 0;

}

Page 20: An Introduction to Object Oriented CSS

Maintainable

[class*='ch-box'] {border-radius: 20px;padding: 10px;margin: 0 0 10px 0;

}

Page 21: An Introduction to Object Oriented CSS

2 Principles

1. Separation of Structure from Skin

2. Separation of Containers from Content

Page 22: An Introduction to Object Oriented CSS

What’s Content?

Page 23: An Introduction to Object Oriented CSS
Page 24: An Introduction to Object Oriented CSS

What’s Container?

Page 25: An Introduction to Object Oriented CSS

http://www.html5code.com/tutorials/html5-semantic-layout-tags/

Page 26: An Introduction to Object Oriented CSS

Break the dependency between content and container

(So you can put the content in different containers)

Page 27: An Introduction to Object Oriented CSS

Use styles that are

specific to an element and

don’t depend on location

Page 28: An Introduction to Object Oriented CSS
Page 29: An Introduction to Object Oriented CSS
Page 30: An Introduction to Object Oriented CSS

The Recipe1. Identify the pattern 2. Create a component library3. Extend it

http://www.flickr.com/photos/mlazarevski/8108416027/sizes/l/in/photostream/

Page 31: An Introduction to Object Oriented CSS
Page 32: An Introduction to Object Oriented CSS

What’sThePattern?

Page 33: An Introduction to Object Oriented CSS
Page 34: An Introduction to Object Oriented CSS

How did we code this?

Page 35: An Introduction to Object Oriented CSS

How did we code this?

Page 36: An Introduction to Object Oriented CSS

How did we code this?

Page 37: An Introduction to Object Oriented CSS
Page 38: An Introduction to Object Oriented CSS
Page 39: An Introduction to Object Oriented CSS

Pattern = Reusable(and consistency)

Page 40: An Introduction to Object Oriented CSS

Create a component

Page 41: An Introduction to Object Oriented CSS
Page 42: An Introduction to Object Oriented CSS
Page 43: An Introduction to Object Oriented CSS
Page 44: An Introduction to Object Oriented CSS

Extend

Page 45: An Introduction to Object Oriented CSS
Page 46: An Introduction to Object Oriented CSS
Page 47: An Introduction to Object Oriented CSS
Page 48: An Introduction to Object Oriented CSS
Page 49: An Introduction to Object Oriented CSS

Too similar?Choose one!

Page 50: An Introduction to Object Oriented CSS

Extend more

Page 51: An Introduction to Object Oriented CSS

Exceptions

Page 52: An Introduction to Object Oriented CSS
Page 53: An Introduction to Object Oriented CSS
Page 54: An Introduction to Object Oriented CSS

Not bad

Page 55: An Introduction to Object Oriented CSS

But it is really necessary?

Page 56: An Introduction to Object Oriented CSS

Today

7 badgesSaved 18+ repeated declarations

Page 57: An Introduction to Object Oriented CSS
Page 58: An Introduction to Object Oriented CSS
Page 59: An Introduction to Object Oriented CSS
Page 60: An Introduction to Object Oriented CSS
Page 61: An Introduction to Object Oriented CSS

20 badgesSaved 57+ repeated declarations

Page 62: An Introduction to Object Oriented CSS
Page 63: An Introduction to Object Oriented CSS

And that’s just ONE pattern

Page 64: An Introduction to Object Oriented CSS

Think of all the others we can find

http://www.flickr.com/photos/bdesham/2432400623/in/photostream/

Page 65: An Introduction to Object Oriented CSS
Page 66: An Introduction to Object Oriented CSS

and this

Page 67: An Introduction to Object Oriented CSS

and thiscould be just this

Page 68: An Introduction to Object Oriented CSS

Success!

Page 69: An Introduction to Object Oriented CSS
Page 70: An Introduction to Object Oriented CSS

This could be very tempting...

Page 71: An Introduction to Object Oriented CSS

But what if it changes?

Page 72: An Introduction to Object Oriented CSS
Page 73: An Introduction to Object Oriented CSS

Future-proof

Page 74: An Introduction to Object Oriented CSS

Don’t forget about semantics

Embrace Semantics

Page 75: An Introduction to Object Oriented CSS

To sum it up...

Page 76: An Introduction to Object Oriented CSS

If you have to copy and paste just one single CSS declaration...

Page 77: An Introduction to Object Oriented CSS
Page 78: An Introduction to Object Oriented CSS

( Tweet me at @Taly )

Page 79: An Introduction to Object Oriented CSS

● http://oocss.org/

● http://www.slideshare.net/stubbornella/object-oriented-css

● http://www.slideshare.net/stubbornella/what-is-object-oriented-css

● https://www.youtube.com/watch?v=EW8NAFELWzo

● http://www.stubbornella.org/content/2010/06/25/the-media-object-saves-hundreds-of-lines-of-code/

● http://www.slideshare.net/stubbornella/5-mistakes-of-massive-css

● http://www.lukew.com/ff/entry.asp?1049

● http://coding.smashingmagazine.com/2011/12/12/an-introduction-to-object-oriented-css-oocss/

● http://www.sitepoint.com/css-architectures-scalable-and-modular-approaches/

● https://www.google.com.ar/search?q=OOCSS

Resources