OOCSS And The Life-Altering Awesomeness That Is Modular CSS Architecture
Prepared for the SEM.js Birthday Bash at Nutshell in Ann Arbor, Michigan on May 12, 2014
3. WHAT IS
MODULAR CSS
ARCHITECTURE?
(It’s freaking awesome, that’s what.)
!
!
The abstraction of repetition into reusable "objects".
4. FRONTEND OBJECTS
Naming Conventions Semantic .content, .news__title, .callNow
Presentational .grid__col—-9, .btn—-small
Modules with states .btn, .btn—primary, .btn—disabled.
Classes vs. IDs vs. Element Selectors Take that, specificity!
5. MODULAR CSS GOALS
Modularity (duh)
Added new page.Wrote 0 lines of CSS.WIN.
Predictability
Hey! I know how to construct a new thing!
Maintainability
Oh, you wanted a big button? .btn--large. BOOM.
Scalability
I got 99 problems, but specificity ain't one.
Flexibility
Mixin' & Matchin’
DRY & Organized
…ability. That’s just plain smart.
6. MODULAR CSS GOALS
Modularity (duh)
Added new page.Wrote 0 lines of CSS.WIN.
Predictability
Hey! I know how to construct a new thing!
Maintainability
Oh, you wanted a big button? .btn--large. BOOM.
Scalability
I got 99 problems, but specificity ain't one.
Flexibility
Mixin' & Matchin’
DRY & Organized
…ability. That’s just plain smart.
A WHOLE
LOT OF
WIN!
10. CONTAINER VS CONTENT
• An Object should look the same no
matter where you put it.
• AVOID Location-Dependent Styles
(which often leads to duplication)
.categoryList h2 {
// BAD! h2 styles are location
// dependent
}
!
.categoryHeader {
// GOOD! We can reuse this header
// style anywhere
}
Assurances
• All h2s will look like h2s.
• All .categoryHeaders will look like .categoryHeaders
<h2 class=“categoryHeader”></h2>
11. BUT CLASSITIS?!? SEMANTICS?!?
Is this going to bloat my HTML markup with classes? Yes.
Is that a bad thing? Shrug.
What about semantics?! It’s complicated.
14. QUESTIONS? AMA!
Slides & Resources: http://bit.ly/sem_oocss
!
@jewlofthelotus
Girl Develop It Ann Arbor
Launch Party w/ Pillar @ The Forge
June 4th 6:30pm
RSVP @ meetup.com
Hey, look!
A media object!