An introduction to Object Oriented CSS

25
Kelley Walker, Dominion Enterprises

Transcript of An introduction to Object Oriented CSS

Page 1: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

Page 2: An introduction to Object Oriented CSS

Object Oriented CSS

a distillation of Nicole Sullivan’s approach to building large, scalable, high traffic

sites and applications

Page 3: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

OOCSS the Sullivan Way

Who is Nicole Sullivan?

www.stubbornella.org

Yahoo: scalability and focus on page speed

Full Six: a French firm experiencing a severe shortage of senior level UI developers, but plenty of graphic designers

Page 4: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

DefinitionsModular: combinable, reusable, extensible

Light: one to many relationship between CSS and potential layouts

Fast: Minimal HTTP requests and minimal size

Future-proof: maintainable, semantic, standards-oriented, easy to redesign, prepared for future browsers

Adaptable: respectful of UX design and marketing restraints

Accessible: SEO, screen readers, variety of user agents, users with disabilities (especially as the population ages), and assistive technologies

Page 5: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

Lego Land

Object oriented

Page 6: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

1. Immature 2. Fragile3. Re-use is Rare

What’s Wrong with CSS?

Page 7: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

Sullivan’s Complaints

1) Coders are writing modules that are too clever.

2) Can’t pull a module and use it elsewhere because code is dependent on that location.

Page 8: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

Questions1. Is the code really too clever?2. Is it possibly because she’s speaking from a

position of working with large organizations -- which don’t typically allow time to write re-usable code?

3. In smaller agencies, might code re-use be more likely because building entire sites with more frequency?

4. OTOH, maybe agency environments might also encourage tendency to try out new tricks – which could mean you are not re-purposing when possible?

Page 9: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

CSS Doesn’t Suck(We’re just doing it wrong)

The way to do it right is to use Object Oriented approaches to building modules, pages, and entire Web sites.

Page 10: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

What is Object Oriented CSS?What does the “object” in

object-oriented mean?

An object exemplifies – is an exemplar of – a class.

A dog with a hat |= object

Page 11: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

•Dog with a hat

•Dog with a bone

•Man with a bone

Page 12: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

Each of those images constitutes a module, not an object. The objects are the man and the bone.

Do we mean this? Or this?

What about a man eating fish?

Page 13: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

OOCCS: Two Characteristics1). Separation of structure and skin

Create basic layouts – like wireframes – then skin the layout.

2). Separation of container and content

Create module containers, then fill with content objects: Header, footer, titles, paragraphs, images, captions, etc.

Page 14: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

Used to focus here:ul{…}ul li{…}ul li a{…}

But, the architecture lives here:ul{…}ul li{…}ul li a{…}

Page 15: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

Objects are Lego-like components that can be mixed and matched to build modules, pages, Web sites.

Page 16: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

This is a module

HEADING

Title Goes HereDescription text goes here. It has the form of a paragraph and, semantically, it is a paragraph.

This is an

Unordered list

Containing examples

These are objects

Page 17: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

OOCSS Top Ten1. Create Component

Library2. Consistent

semantic styles3. Design modules to

be transparent on the inside

4. Be flexible5. Use grids

6. Minimize selectors7. Separate structure

and skin8. Separate container

and content9. Use reset and font

consistency style sheets (@YUI)

10.Extend objects with multiple classes

Page 18: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

Do’s Do develop pages after all individual structural

elements have been identified Do build structural legos first Do use grids: grids control width; content

controls height Do abstract reusable elements Do style for exceptions Do set objects - not pages or modules Do set global defaults on content objects

Page 19: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

Do’sThis is the norm: .error{ most of the code goes here }

These are exceptions:div.error{…;}p.error{…;}span.error{…;}

Page 20: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

Don’tsDepending on the cascade is not Object Oriented CSS:

h3{color:black;}.weathermodule h3 {color:red;}.nav_tabs h3{color:blue;}

Instead, she argues for a global definition of heading tags:

h1, .h1{…}, h2, .h2{…}, h3, .h3{…}, h4, .h4{…}, h5, .h5{…}, h6, .h6{…}

Page 21: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

Don’ts Don’t specify elements (only if it’s an exception) div.myclass{…} instead, use: .myclass{…}

Don’t use IDs - reserve for use as javascript hooks

Page 22: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

Don’ts

Don’t use height alignment in the design

Bowralite maricaMahewu's nondecisiveness bisetous sexly nonurgently gutteral tingidae politei amphioxidae fibromyomectomy admiredly. Uninsolated topepo balbusard aristocraticism falcular gmelinites. Centrodorsally boghole armadilla subarborescence prederived distater deliquiate.

Semicardinal subslots legative plasmode langsettle tummer preboyhood's, outmalaprop hydroguret runagado, reexpression abatage's disomatic. Heteroside harten braggadocian cattlefold indiadem patheticis todo ally porcelanic xanthophyl.

Semicardinal subslots legative plasmolangsettle tummer preboyhood's, outmalaprop hydroguret runagado, reexpressabatage's disomatic. Heteroside harten braggadocian cattlefold indiadem patheticis todo ally porcelanic xanthophyl.

Page 23: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

Semicardinal subslots legative plasmode langsettle tummer preboyhood's, outmalaprop hydroguret runagado, reexpression abatage's disomatic. Heteroside harten braggadocian cattlefold indiadem patheticis todo ally porcelanic xanthophyl.

Because… when your content is dynamic….Bowralite maricaMahewu's nondecisiveness bisetous sexly nonurgently gutteral tingidae politei amphioxidae fibromyomectomy admiredly. Uninsolated topepo balbusard aristocraticism falcular gmelinites. Centrodorsally boghole armadilla subarborescence prederived distater deliquiate.

Semicardinal subslots legative plasmolangsettle tummer preboyhood's, outmalaprop hydroguret runagado, reexpressabatage's disomatic. Heteroside harten braggadocian cattlefold indiadem patheticis todo ally porcelanic xanthophyl.

Page 24: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises

Communicating Object Oriented CSS:

Page 25: An introduction to Object Oriented CSS

Kelley Walker, Dominion Enterprises