object oriented css graeme blackwood

60
Object Oriented CSS Creative Director Deeson Online twitter.com/ graemeblackwood Graeme Blackwood

Upload: drupalconf

Post on 15-Jun-2015

364 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Object oriented css graeme blackwood

Object Oriented CSS

Creative Director

Deeson Online

twitter.com/graemeblackwood

Graeme Blackwood

Page 2: Object oriented css graeme blackwood

2

Спонсоры

Генеральный спонсор

Серебряный спонсор Серебряный спонсор

Бронзовый спонсор Бронзовый спонсор

Организатор

Page 3: Object oriented css graeme blackwood

Graeme

Blackwood Creative Director, Deeson Online

deeson-online.co.uk

@graemeblackwood

Graeme

Blackwood Creative Director, Deeson Online

deeson-online.co.uk

@graemeblackwood

Page 4: Object oriented css graeme blackwood

Object Oriented CSS

Object Oriented CSS

Page 5: Object oriented css graeme blackwood

PropsProps• Nicole Sullivan, http://www.stubbornella.org

• Jonathan Snook (SMACSS), http://smacss.com

• Everyone at http://thesassway.com

• Chris Eppstein, http://compass-style.org

• Kevin Poulton http://www.flickr.com/photos/kevinpoulton

• And loads more!

Page 6: Object oriented css graeme blackwood

Some misconceptions

Some misconceptions

Page 7: Object oriented css graeme blackwood

OO CSS !=OO Programming

But an OOP mindset can be applied to CSS

OO CSS !=OO Programming

But an OOP mindset can be applied to CSS

Page 8: Object oriented css graeme blackwood

OOCSS does not require any newer technologies

It works in IE6 – no need for CSS3, HTML5 etc

OOCSS does not require any newer technologies

It works in IE6 – no need for CSS3, HTML5 etc

Page 9: Object oriented css graeme blackwood

Semantic markup is very helpful, but usually not essential

Semantic is better though!

Semantic markup is very helpful, but usually not essential

Semantic is better though!

Page 10: Object oriented css graeme blackwood

The traditional approach to CSSThe traditional

approach to CSS

Page 11: Object oriented css graeme blackwood

Style output as needed Each item / page individually...

Style output as needed Each item / page individually...

Page 12: Object oriented css graeme blackwood

Target styles by drilling down through nested elements

Page 13: Object oriented css graeme blackwood

Problems with traditional CSS

Page 14: Object oriented css graeme blackwood

Coding takes a lot longer

Page 15: Object oriented css graeme blackwood

It gets bloated

Page 16: Object oriented css graeme blackwood

It is difficult to read and hard to reuse

Page 17: Object oriented css graeme blackwood

Traditional CSS is tough to maintain

Page 18: Object oriented css graeme blackwood

Page 19: Object oriented css graeme blackwood

Object Oriented CSSA new way of thinking

Page 20: Object oriented css graeme blackwood

Separate layout from theme(Use a grid system!)

Page 21: Object oriented css graeme blackwood

Separate the container from the content

Page 22: Object oriented css graeme blackwood

Look for shared stylesYou will see them everywhere

Page 23: Object oriented css graeme blackwood

Why should I care?

Why should I care?

Page 24: Object oriented css graeme blackwood

Reusable code

Page 25: Object oriented css graeme blackwood
Page 26: Object oriented css graeme blackwood

QuickTime™ and aH.264 decompressor

are needed to see this picture.

Faster development

Less effort to code

Page 27: Object oriented css graeme blackwood

Easier to maintain

Page 28: Object oriented css graeme blackwood
Page 29: Object oriented css graeme blackwood
Page 30: Object oriented css graeme blackwood

Less code,smaller files

Page 31: Object oriented css graeme blackwood

Getting started

Page 32: Object oriented css graeme blackwood

Using a grid system?You are already on the right track!

Page 33: Object oriented css graeme blackwood

Use a reset stylesheet

HTML5 boilerplate’s normalize.css

Page 34: Object oriented css graeme blackwood

Set good base stylesTo minimise later overrides

* {box-sizing: border-box} is pretty handy

Page 35: Object oriented css graeme blackwood

Set good base stylesTo minimise later overrides

Build HTML prototypeswith Drupal in mind...

Page 36: Object oriented css graeme blackwood

Clean up what Drupal throws at youDon’t just style,theme!

Page 37: Object oriented css graeme blackwood

Lose unnecessary markup if it affects you

Some divs are totally pointless!

Page 38: Object oriented css graeme blackwood

PHP code not for you?

I find Drupal modules likeDisplay Suite and Skinr helpful

PHP code not for you?

I find Drupal modules likeDisplay Suite and Skinr helpful

Page 39: Object oriented css graeme blackwood

Check out TWIG

We’re working on making Drupal 8 a lot easier to theme.

http://twig.sensiolabs.org/

Check out TWIG

We’re working on making Drupal 8 a lot easier to theme.

http://twig.sensiolabs.org/

Page 40: Object oriented css graeme blackwood

Don’t be too obsessed with perfect markup

Just enough is ok

Page 41: Object oriented css graeme blackwood

“Now, this is just a simulation of what the blocks will look like once they’re assembled”

Page 42: Object oriented css graeme blackwood

Let’s look at some real world applications...

Let’s look at some real world applications...

Page 43: Object oriented css graeme blackwood

.block = inherited base styles only.grid-4 = grid class.theme-a

= theme class, H3 and p inherit colour.padded is a class I add

to the grid framework for situations like this

Page 44: Object oriented css graeme blackwood

<div class=”grid-4 theme-a block”> <h3>Block title</h3> <p>Hello world!</p></div>

.grid-4 comes from your grid framework

.theme-a { background-color: #580174; border-radius: 6px; color: #fff; //H3 and p inherit this}

Page 45: Object oriented css graeme blackwood

Carousel nav tabsObject is a Drupal

menu – UL with a class of .sidebar-menu. Custom jQuery targets the ID.

Page 46: Object oriented css graeme blackwood

Also used on a listingAnd it flexes to the container

Page 47: Object oriented css graeme blackwood

99% of the styles are reused, targeted through .right .sidebar-menu only to flip the active item

Page 48: Object oriented css graeme blackwood

Carousel itemsWith a class of .product-box

Page 49: Object oriented css graeme blackwood

Reused on listing pages

Page 50: Object oriented css graeme blackwood

Same layout as product listings and carousel, flexed to image size

Page 51: Object oriented css graeme blackwood

What aboutSASS and LESS?

Why bother with presentational classes in markup anymore?

What aboutSASS and LESS?

Why bother with presentational classes in markup anymore?

Page 52: Object oriented css graeme blackwood

Not everyone wants to use a CSS preprocessorAnd the mindset of reduce, reuse & recycle is just as important even with oneNot everyone wants to use a CSS preprocessorAnd the mindset of reduce, reuse & recycle is just as important even with one

Page 53: Object oriented css graeme blackwood

Use SASS wisely – it’s another layer to debug

Use SASS wisely – it’s another layer to debug

Page 54: Object oriented css graeme blackwood

Be particularly careful with nested selectors http://thesassway.com/beginner/the-inception-rule

http://37signals.com/svn/posts/3003-css-taking-control-of-the-cascade

Be particularly careful with nested selectors http://thesassway.com/beginner/the-inception-rule

http://37signals.com/svn/posts/3003-css-taking-control-of-the-cascade

Page 55: Object oriented css graeme blackwood
Page 56: Object oriented css graeme blackwood

Disregarding the other principles of OOCSS may create pain later

You could end up with generated CSS bloated even more than if you had hand-coded it

Page 57: Object oriented css graeme blackwood

SummarySummary• OOCSS is as much a mindset as a technique

• The principles are to reduce, reuse and recycle code

• This is done through separating layout from theme

• and the container from the content

• It relies primarily on reused classes and markup

• We are working on Drupal 8 to make it much easier to change markup. In the meantime, try Display Suite or Skinr for node theming

• OOCSS is as much a mindset as a technique

• The principles are to reduce, reuse and recycle code

• This is done through separating layout from theme

• and the container from the content

• It relies primarily on reused classes and markup

• We are working on Drupal 8 to make it much easier to change markup. In the meantime, try Display Suite or Skinr for node theming

Page 58: Object oriented css graeme blackwood

SummarySummary

• CSS preprocessors like SASS and LESS are great

• But they create another layer to debug

• And the code they generate can be very bloated

• Preprocessors are not an excuse to be lazy

• They still need to be used with an OO mindset

• CSS preprocessors like SASS and LESS are great

• But they create another layer to debug

• And the code they generate can be very bloated

• Preprocessors are not an excuse to be lazy

• They still need to be used with an OO mindset

Page 59: Object oriented css graeme blackwood

Спасибо за внимание

Вопросы?

Creative Director

Deeson Online

@graemeblackwood

Graeme Blackwood

Page 60: Object oriented css graeme blackwood

60

Спонсоры

Генеральный спонсор

Серебряный спонсор Серебряный спонсор

Бронзовый спонсор Бронзовый спонсор

Организатор