The first time I heard about Object Oriented CSS was from a tutorial on NetTuts. At the time, I viewed OOCSS as just another random framework somebody was imposing on the web community. I had not given it much thought since then, until I listened to Nicole Sullivan‘s interview on The Big Web Show. She’s a CSS pro who started OOCSS.org and the open-source OOCSS project on github. Nicole has been hired by mega-sites like Facebook to optimize their CSS files. FACEBOOK! That must have been insane!
Oh, OOOOOOOOOh CSS!
Having spent a chunk of the last 4 years of my life learning and working with CSS on a daily basis, I was intrigued to hear the thoughts of an elite CSS Ninja. Half way through the interview I found myself inspired to become an Object Oriented CSS-er.
I started browsing the Google tubes and found a nifty presentation created by Nicole: The Fast and the Fabulous
If you didn’t have time to click through the slideshow here is a super tiny break down:
Two main principles
- Separate structure and skin
- Separate container and content
Applying these principles creates efficient CSS code. This means cleaner smaller CSS files that load faster.
What does it look like?
This basic structure is very flexible. By adding classes you can “extend” the object class to fit each scenario the design requires. For example:
[html]<div class=”object simple half”> …[/html]
Extending the object class is faster to write and to load.
I’m extremely guilty of writing overly specific CSS, thinking that everything has to have its own ID. Trying to be too semantic, I guess. I’ve confused myself by listening to too many different theories about how to structure your HTML and how to reference selectors in your CSS files.
I’m realizing that all I’ve needed was a little objectivity.