SlideShare a Scribd company logo
Object
Oriented
CSS
Graeme Blackwood
Creative Lead, Deeson Online


deeson-online.co.uk
@graemeblackwood
Props
• 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!
Before we get going
OO CSS !=
OO Programming

But an OOP mindset can be
applied to CSS
OOCSS does not
require any newer
technologies

It works in IE6 – no need for CSS3,
HTML5 etc
Semantic markup is
very helpful, but
usually not essential

Semantic is better though!
The traditional
approach to CSS
Style output
as needed
Each item / page
individually...
Target styles by
drilling down
through nested
elements
Problems with
traditional CSS
Coding takes
a lot longer
It gets
bloated
It is difficult to read
and hard to reuse
Traditional CSS is
tough to maintain
‽
Object Oriented CSS
A new way of thinking
Separate layout from theme
(Use a grid system!)
Separate the container
from the content
Look for shared styles
You will see them everywhere
Why should
I care?
Reusable code
Object Oriented CSS for rapid, scalable and maintainable development
Faster
development




Less effort to code
Easier to maintain
Object Oriented CSS for rapid, scalable and maintainable development
Object Oriented CSS for rapid, scalable and maintainable development
Less code,
smaller files
Getting started
Using a grid system?
You are already on the right track!
Use a reset
stylesheet
HTML5
boilerplate’s
normalize.css
Set good base styles
To minimise later overrides

* {box-sizing: border-box} is pretty handy
Set good base styles
Build HTML prototypes
To minimise later overrides
with Drupal in mind...
Clean up what Drupal
throws at you
Don’t just style,
theme!
Lose unnecessary
markup if it affects you
            Some divs are
            totally pointless!
Don’t be too obsessed
with perfect markup
Just enough is ok
“Now, this is just a simulation of what the blocks
    will look like once they’re assembled”
Let’s look at some real
world applications...
.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
<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
}
Carousel nav tabs
Object is a Drupal menu – UL with a class of .sidebar-menu.
Custom jQuery targets the ID.
Also used on a listing
And it flexes to the container
99% of the styles are
reused, targeted
through .right .sidebar-menu
only to flip the active item
Carousel items
With a class of .product-box
Reused on listing
pages
Same layout as product
listings and carousel, flexed
to image size
What about
SASS and LESS?
Why bother with presentational classes
in markup anymore?
Not everyone wants to
use a CSS preprocessor
And the mindset of reduce, reuse & recycle
is just as important even with one
Use SASS wisely – it’s
another layer to debug
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
Object Oriented CSS for rapid, scalable and maintainable development
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
Summary
• 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
Summary

• 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
Thanks for listening!
Questions?
@graemeblackwood




Most of the fantastic lego images were by Kevin Poulton http://www.flickr.com/photos/kevinpoulton

More Related Content

PPT
Object oriented css graeme blackwood
PDF
LESS is More
PDF
快速开发Css
PDF
SMACSS Workshop
PPTX
Basics of Front End Web Dev PowerPoint
PDF
What's Object-Oriented CSS (japanese)
PDF
CSS with superpowers - SASS!
 
PDF
CSS For Backend Developers
Object oriented css graeme blackwood
LESS is More
快速开发Css
SMACSS Workshop
Basics of Front End Web Dev PowerPoint
What's Object-Oriented CSS (japanese)
CSS with superpowers - SASS!
 
CSS For Backend Developers

What's hot (20)

PDF
CSS Best practice
PPT
Drupal - Introduction to Drupal Template Design
PPT
An Introduction to CSS Frameworks
PDF
Battle of the Front-End Frameworks: Bootstrap vs. Foundation
PDF
Css In Iterations
PDF
What is Modular CSS?
PPTX
Make your CSS beautiful again
KEY
CSS Frameworks
PPTX
HTML/CSS Workshop @ Searchcamp
KEY
WordCamp NYC - DRY CSS
PDF
DrupalCon Austin 2014 Implement Foundation or Other Front-End Frameworks in Y...
PDF
Layout absolute poz
PDF
Foundation vs Bootstrap - CC FE & UX
PPTX
Making Web Fun
DOCX
Untitleddocument (1)
PPTX
PPTX
Hammersmith fundamentals html fundamentals
PDF
Front End Tooling and Performance - Codeaholics HK 2015
PDF
Structuring your CSS for maintainability: rules and guile lines to write CSS
PDF
Object-Oriented CSS 從 OOCSS, SMACSS, BEM 到 AMCSS
CSS Best practice
Drupal - Introduction to Drupal Template Design
An Introduction to CSS Frameworks
Battle of the Front-End Frameworks: Bootstrap vs. Foundation
Css In Iterations
What is Modular CSS?
Make your CSS beautiful again
CSS Frameworks
HTML/CSS Workshop @ Searchcamp
WordCamp NYC - DRY CSS
DrupalCon Austin 2014 Implement Foundation or Other Front-End Frameworks in Y...
Layout absolute poz
Foundation vs Bootstrap - CC FE & UX
Making Web Fun
Untitleddocument (1)
Hammersmith fundamentals html fundamentals
Front End Tooling and Performance - Codeaholics HK 2015
Structuring your CSS for maintainability: rules and guile lines to write CSS
Object-Oriented CSS 從 OOCSS, SMACSS, BEM 到 AMCSS
Ad

Similar to Object Oriented CSS for rapid, scalable and maintainable development (20)

PPT
Object oriented css. Graeme Blackwood
ZIP
OOCSS for Javascript pirates at jQueryPgh meetup
PPTX
Css methods architecture
PDF
OOCSS for JavaScript Pirates jQcon Boston
PDF
Decoupling the Front-end with Modular CSS
PPTX
OOCSS presentation
PDF
Intro to OOCSS Workshop
PDF
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
PDF
CSS - OOCSS, SMACSS and more
PPT
An introduction to Object Oriented CSS
KEY
Slow kinda sucks
KEY
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
PDF
More of less (take 2)
PDF
Atlanta Drupal User's Group - April 2015 - Sasstronauts: Advanced Sass Topics
PDF
Future-proof styling in Drupal (8)
PDF
Object Oriented CSS - Joomla!dagen Nederland 2014
PDF
CSS: a rapidly changing world
KEY
What is Object Oriented CSS?
PDF
Modular HTML & CSS Turbo Workshop
PDF
CSS vs. JavaScript - Trust vs. Control
Object oriented css. Graeme Blackwood
OOCSS for Javascript pirates at jQueryPgh meetup
Css methods architecture
OOCSS for JavaScript Pirates jQcon Boston
Decoupling the Front-end with Modular CSS
OOCSS presentation
Intro to OOCSS Workshop
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
CSS - OOCSS, SMACSS and more
An introduction to Object Oriented CSS
Slow kinda sucks
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
More of less (take 2)
Atlanta Drupal User's Group - April 2015 - Sasstronauts: Advanced Sass Topics
Future-proof styling in Drupal (8)
Object Oriented CSS - Joomla!dagen Nederland 2014
CSS: a rapidly changing world
What is Object Oriented CSS?
Modular HTML & CSS Turbo Workshop
CSS vs. JavaScript - Trust vs. Control
Ad

Recently uploaded (20)

PDF
Emailing DDDX-MBCaEiB.pdf DDD_Europe_2022_Intro_to_Context_Mapping_pdf-165590...
PPTX
Causes of Flooding by Slidesgo sdnl;asnjdl;asj.pptx
PPTX
An introduction to AI in research and reference management
PPTX
Tenders & Contracts Works _ Services Afzal.pptx
PPTX
HPE Aruba-master-icon-library_052722.pptx
PDF
Chalkpiece Annual Report from 2019 To 2025
PDF
GREEN BUILDING MATERIALS FOR SUISTAINABLE ARCHITECTURE AND BUILDING STUDY
PDF
BRANDBOOK-Presidential Award Scheme-Kenya-2023
PDF
Interior Structure and Construction A1 NGYANQI
PPTX
EDP Competencies-types, process, explanation
PPT
WHY_R12 Uaafafafpgradeaffafafafaffff.ppt
PDF
Urban Design Final Project-Site Analysis
PPTX
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
PDF
Quality Control Management for RMG, Level- 4, Certificate
PPTX
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
PPTX
LITERATURE CASE STUDY DESIGN SEMESTER 5.pptx
PPTX
Media And Information Literacy for Grade 12
PPT
UNIT I- Yarn, types, explanation, process
PPTX
Wisp Textiles: Where Comfort Meets Everyday Style
PPT
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
Emailing DDDX-MBCaEiB.pdf DDD_Europe_2022_Intro_to_Context_Mapping_pdf-165590...
Causes of Flooding by Slidesgo sdnl;asnjdl;asj.pptx
An introduction to AI in research and reference management
Tenders & Contracts Works _ Services Afzal.pptx
HPE Aruba-master-icon-library_052722.pptx
Chalkpiece Annual Report from 2019 To 2025
GREEN BUILDING MATERIALS FOR SUISTAINABLE ARCHITECTURE AND BUILDING STUDY
BRANDBOOK-Presidential Award Scheme-Kenya-2023
Interior Structure and Construction A1 NGYANQI
EDP Competencies-types, process, explanation
WHY_R12 Uaafafafpgradeaffafafafaffff.ppt
Urban Design Final Project-Site Analysis
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
Quality Control Management for RMG, Level- 4, Certificate
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
LITERATURE CASE STUDY DESIGN SEMESTER 5.pptx
Media And Information Literacy for Grade 12
UNIT I- Yarn, types, explanation, process
Wisp Textiles: Where Comfort Meets Everyday Style
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt

Object Oriented CSS for rapid, scalable and maintainable development