SlideShare ist ein Scribd-Unternehmen logo
1 von 151
Scalable and Modular CSS
              FTW!
    The Legend of the Birth of MetaCoax




/ * Denise R. Jacobs
Future. Innovation. Technology. Creativity.
Amsterdam, Netherlands
18 February 2013 */
Tweeting tall tales
I am:
@denisejacobs

This fine event is:
@fitc #FITCAms

And I’m telling the tale of:
#metacoax
And tell stories about CSS
I like to make stuff
The Legend of the Birth of
MetaCoax
chapter 1
Problems in Poësia
chapter 2
The Teachings of the Masters
chapter 3
Insights and Epiphanies
chapter 4
Ousting Selector Evil
chapter 5
Triumph!
Chapter 1
Problems in Poësia
You know how all stories start…
There was a Kingdom called
Poësia




                        http://www.flickr.com/photos/drobnikm/525835032/
Emperor Eric
On the surface, all was fine…




                           http://www.flickr.com/photos/trodel/3801987960/
Behind the city’s walls…




                           http://www.flickr.com/photos/kathrynvjones/3737219448/
It was a nightmare of dis-
organization




                             http://www.flickr.com/photos/torley/4096277982/
Top architects and designers




                         http://www.flickr.com/photos/massgovernor/7345462040/
Who hired builders




                     http://www.flickr.com/photos/8533266@N04/4457182603/
Some believed in mastery…




                       http://www.flickr.com/photos/statuelibrtynps/6276757947/
Others were not




                  http://www.flickr.com/photos/anotherjesse/243020629/
Put together with whatever was handy




                           http://www.flickr.com/photos/laughingsquid/142398084
Shabby new structures




                        http://www.flickr.com/photos/cbnsp/6605969807/
They didn’t start off evil




                             http://www.flickr.com/photos/dr_john2005/3934871670/
…but they slowly became so over
time




                          http://www.flickr.com/photos/dr_john2005/3935163348/
Follow suit and try to fit in
Fight by trying to become
!important




                            http://www.flickr.com/photos/stuckincustoms/6199442617/
He sent out his two most trusted
aides…




                              http://www.flickr.com/photos/bbsc30/168832715/
They traveled far and wide…




                         http://www.flickr.com/photos/annegirl/435308460/
And found the prophet Marcot




                         http://www.flickr.com/photos/axsdeny/2607122395/
The gospel of Responsive
He spoke of a championne




                       http://www.flickr.com/photos/44085287@N05/4055807492/
They traveled south to Mijami…




                                 Photo: Denise Jacobs
To find Djieh and Djinn!
Chapter 2
The Teachings of the Masters
They went deep into the canyons




            http://www.flickr.com/photos/gods-art/6622668251/
The Dry Wind appeared to them




            http://www.flickr.com/photos/gods-art/6622669139/
DRY CSS



http://www.slideshare.net/jeremyclarke/dry-css-
a-dontrepeatyourself-methodology-for-creating-
efficient-unified-and-scalable-stylesheets
DRY CSS


“Don’t Repeat Yourself”

Never repeat a style/property definition…ever.
DRY CSS: Thinking


When looking at making a style declaration for a
selector, always have an answer to the question
"Why isn’t this part of a group?”
Then figure out how to make it one.
DRY CSS: Approach

Groups define shared properties.

Group selectors with shared properties, rather
than defining them separately.

While the groups have many selectors, each
property/value pair is defined only once.
DRY CSS: How

• Name the groups based on their role in the
  design

• Use the name as an ID at the top of the list
  and a class at the bottom

• Group selectors that share properties above
  the properties they share
For example
#LIGHT-WHITE-BACKGROUND,
.translation,
.entry .wp-caption,
#full-article .entry img,
.recent-comment .comment-text,
.roundup h3,
.post-header-sharing,
#post-categories td.label,
#post-archive roundup h3,
.subscription-manager ol,
.light-white-background
{
  background-color: #fff;
  border-color: #ccc;
}
The Ninja




            http://www.flickr.com/photos/branditressler/2912153888/
OOCSS



Object Oriented CSS

https://github.com/stubbornella/oocss/wiki
Was ruthless
Outcome


  CSS bytes/page   HTML bytes/page



  19% 44%
     decrease         decrease
OOCSS: Signs you need it

• Large number of floats = bad grid

• Large number of margins = you need a reset
  css

• Large number of font-size & !important =
  cascade is not being leveraged
OOCSS: The Gist
• Employ DRY

• Separate structure and presentation

• Modularize
OOCSS: Do’s
• Use CSS grids

• Keep selector chains as short as possible

• Give rules the same weight/strength

• Use <hr> as a page section delimiter

• Style classes rather than elements
OOCSS: Don’ts
• Avoid attaching classes to elements

• Avoid using IDs as styling hooks, use them for JS
  hooks and page anchors

• Avoid the descendent selector

• Don’t over-semanticize class names

• Avoid classnames that are related to the
  appearance of the style
OOCSS: The process
1. Determine the site-wide “legos” (ie, reusable
   pieces)
2. Separate
  – Container and Content
  – Structure and Skin
  – Contour and Background
  – Objects and Mix-ins
3. Mix and match container and content objects
   to achieve high performance design.
4. Skin for visual difference
OOCSS: The Media Module




             http://www.stubbornella.org/content/2010/06/25/the-media-object-saves-hundreds-of-lines-of-code/
OOCSS: The Media Module
<!-- media -->
<div class="media">
   <img class="fixedMedia" src="myImg.png" />
   <div class="text">
   ...
   </div>
</div>
OOCSS: The Media Module

/* ====== media ====== */
.media {margin:10px;}
.media, .bd {overflow:hidden; _overflow:visible;
zoom:1;}
.media .img {float:left; margin-right: 10px;}
.media .img img{display:block;}
.media .imgExt{float:right; margin-left: 10px;}
The Lumberjack




                 http://www.flickr.com/photos/stikeymo/308546507/
SMACSS



Scalable and Modular Architecture for CSS

https://smacss.com/
SMACSS: Style categories


•   Base
•   Layout
•   Module
•   State
•   Theme
SMACSS: Curb your enthusiasm



Selectors should be “shallow” instead of “deep”

Strive for the shallowest possible.
SMACSS: Deep selector



div#childrens-footer div#col2.column
div.bestRight p.bestTitle
SMACSS: Shallow selector




p.bestTitle
SMACSS: Shallow selectors 101

• Avoid tag selectors for common elements
  unless completely predictable.

• Use class names as the right-most (key)
  selector

• Use the child selector
SMACSS: On “classitis”

You’re better off adding classes to the elements
in question and repeating the class in the HTML
than having overly-specific styles.

Instead of being classitis, using multiple classes
clarifies intent and increases the semantics of
elements in question.
SMACSS: Module candidates

•   Nav bars
•   Carousels
•   Dialogs
•   Widgets
•   Tables
•   icons
SMACSS: States

State changes can be notated by class names
like

.is-active
.is-collapsed
.btn-pressed
SMACSS: What’s in a name?
an example module:
.example

a callout module:
.callout

a callout module with a collapsed state:
.callout.is-collapsed
SMACSS: Words of Wisdom



“Constrain, but don’t choke.

Consider selector performance, but don’t waste
too much time on it.”
The Brit




           http://www.flickr.com/photos/31363949@N02/6958447097/
CSS For Grown Ups


https://speakerdeck.com/u/andyhume/p/css-for-
grown-ups-maturing-best-practises

http://schedule.sxsw.com/2012/events/event_IA
P9410 (audio)
He lived his own nightmare




                             http://www.flickr.com/photos/djrue/4835062638/
CSS For Grown Ups



Don’t style pages, style modules.

Have a style module library that you can reuse.
CSS For Grown Ups

Think of your styles as being in layers:
• document – from HTML code, element
  selectors
• base styles
• module styles
• layout styles
CSS For Grown Ups


Easy determination:
A tag as part of the selector = a document style

If you create a class for it, you release it from
the tag and make it a module style.
CSS For Grown Ups: Don’t

…make modules variations based on IDs, base
them on classes instead

#sidebar .promo-box = bad

.promo-box { ... } = okay

.promo-box-light { ... } = better!
CSS For Grown Ups: Modules
.promo-box

Related/sub-styles: module’s name extended
with two dashes
.promo-box--eco

javascript class prefixed with js:
.js-login
CSS For Grown Ups: Typography



.h-headline
.h-subheadline
.h-byline
.h-promo
CSS For Grown Ups: Helpers


“Surgical layout helpers” which are things like
paddings, margins, and gutters as separate
classes.

.margin-top {margin-top: 1em;}
Chapter 3
Insights and Epiphanies
The Masters all speak the same
truths




                         http://www.flickr.com/photos/s4xton/2425718415/
Their teachings
• Ids? Not so much.

• Classes? Aww yeah!

• With selectors, less is more

• Get your module on

• Naming conventions? !Important
Can be simplified to this:


• Structure and Inform

• Reduce

• Recycle and Reuse
Structure and Inform




                       http://www.flickr.com/photos/trvance/3138749670/
Structure and Inform

• Utilize a naming convention to establish
  structure and meaning

• Categorize styles in the document or into
  multiple documents

• Employ grids for consistent page structure
Reduce
Reduce

• Eliminate inline styles

• Write the shortest chain of elements possible
  in selectors

• Drop elements: as qualifiers and selectors

• Choose classes over ids
Recycle & Reuse




                  http://www.flickr.com/photos/epsos/5575089139/
Recycle & Reuse

• Leverage the cascade better to cut down on
  redundant style declarations

• Modularize page components to reuse
  throughout site

• Extend modules through subclassing
They figured out the key!




             http://www.flickr.com/photos/karent/3673326282/
What do you do when you build?




                         http://www.flickr.com/photos/mdave/2878687949/
Exactly!




           http://www.flickr.com/photos/chriscoyier/5269340772/
What should we call it? Hmmm…

measure twice, cut once css 

mtco css 

meta coa css 

MetaCoax!
And thus, MetaCoax was born!


      { Measure twice: cut once; }
Djiejh and Djinn went to Poësia…




             http://www.flickr.com/photos/trodel/3801987960/
Chapter 4
Ousting Selector Evil
Institute change in 3 phases




              .flickr.com/photos/boklm/486646798/
(1) Initial phase



• Optimize selectors

• Reduce the redundant
Optimize Selectors


• Eliminate qualifier selectors [oocss]

• Eliminate the middleman

• Have the shortest chain possible
  [oocss, smacss]
Qualified selectors



       div#           div.

   1259               836
Eliminate qualifier selectors

Selectors like
div#widget-nav div#widget-nav-slider ul li
div.name span

Could easily be simplified into
#widget-nav-slider .name span

with the exact same outcome.
Eliminate the middleman

If you must use a descendent selector, then
eliminate all unnecessary elements in it:
.widget li a

would become
.widget a
Have the shortest chain possible


For example, instead of
#toc > LI > A

it’s better to create a class, such as
.toc-anchor
Reduce the Redundant


• Leverage the cascade by relying on
  inheritance [oocss]

• Review, revise and reduce !important
  [oocss, smacss]
Leverage the cascade with
inheritance
color
font-family
font-size
font-style
font-variant
font-weight
font
line-height
list-style-image
list-style-position
list-style-type
list-style
text-align
text-indent
text-transform
visibility
white-space
word-spacing
Not using the cascade



      font          font-size

    100             112
Review, revise and reduce
!important



If there are a lot of styles that are !important
then…
UR DOIN’ IT WRONG
For example…


         !important

          126
(2) Intermediate phase
• Clear the cruft

• Create preliminary portable styles [cfgu]

• Begin instituting modules based on design
  patterns [oocss, smacss, cfgu]

• Institute a Grid [oocss]
Clear the cruft
• Eliminate inline styles & decrease use of
  <span>

• Eliminate styles that rely on qualifiers high in
  the DOM [oocss]

• Use classnames as key selector [smacss]

• Create preliminary portable styles [cfgu]
Eliminate styles that rely on qualifiers
high in the DOM

body.video div#lowercontent
div.children.videoitem.hover a.title {
background: #bc5b29;
color: #fff !important;
text-decoration: none;
}
Too high in the DOM


             body#

            936
Create preliminary portable styles



• Typographic classes for headings, etc.[cfgu]

• Surgical layout helpers [cfgu]
Is surgery necessary?



    margin-top    margin-bottom


    189             112
Institute a Grid



• Use CSS3 box-sizing

• Make the grid and images fluid
Bad grid



      width   margin


    327       738
Good grid

.l-col-1-1 {float:none;}
.l-col-1-2 {width:50%; *width:43%; }
.l-col-1-3 {width:33.33333%; *width:32.33333%;}
.l-col-2-3 {width:66.66666%; *width:65.66666%;}
.l-col-1-4 {width:25%; *width:23%; }
.l-col-3-4 {width:75%; *width:72%;}
.l-col-1-5 {width:20%; *width:19%;}
.l-col-2-5 {width:40%; *width:39%;}
.l-col-3-5 {width:60%; *width:59%;}
.l-col-4-5 {width:80%; *width:79%;}
.l-col-1-6 {width:16.6%; *width:15.6%;}
Make the grid and images fluid


img {
max-width: 100%;
height: auto;
}
(3) Advanced phase


• Continue modularizing page elements
  [ocss, smacss, cfgu]

• Continue cleaning-up selectors and styles

• Separate CSS files by category [smacss]
Chapter 5
Triumph!
Structure




            http://www.flickr.com/photos/joebehr/6349047969/
Inbred selectors banished




                            http://i31.photobucket.com/albums/c351/Rasey07/twins.jpg
Ended the Specificity Wars
Ready for a responsive future




                          http://www.flickr.com/photos/digitalfrance/98314057/
New best practices




                     http://www.flickr.com/photos/torley/2761300969/
Reset with Normalize.css




                           http://necolas.github.com/normalize.css/
Use a better Clearfix


Still using this?

<div class="clear"></div>
…
.clear { clear: both; }
The New Clearfix
/* For modern browsers */
.cf:before, .cf:after {
 content:"";
display: table;
}

.cf:after { clear: both;}

/* For IE 6/7 (trigger hasLayout) */
.cf { *zoom:1; }
And a better Divider
Seriously?

<div class="divider"></div>
…
div.divider {
border-top: 1px solid #ABAA9A;
clear: both;
}
The Ninja says




<hr>
…And Image replacement


.hide-text {
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
}
Use an icon element

Instead of this:

<li class="favorite">
<span class="icon favorite"></span>
<span id="favorite-poem-insert-point"
class="favorite"></span>
</li>
Use an icon element

Do this:

<p><i class="icon icon-comment"></i>23
comments</p>
...
.icon {background-image: url( sprites.png ); }

.icon-comments {background-position: 0 -30px; }
Share the Love
Just revamping the code isn’t
enough…


“Even the cleanest code gets ruined by the first
non-expert to touch it.”

- Nicole Sullivan,
The Cascade, Grids, Headings, and Selectors
from an OOCSS Perspective
Website styleguide




                     http://www.flickr.com/photos/littlemad/5729783584/
Styleguide Creation Process
1. Determine the unique elements and components
   that will be in the styleguide. Also notate the
   main colors for text, header, links, and buttons.

2. Start styling the core elements of the pages:
   headings, links, tables, blockquotes, unordered
   and ordered lists, and forms.

3. Style the components that override the base
   styles, such as search boxes, breadcrumb
   navigation, themed buttons, and variations in
   modules. Include interaction styles:
   hover, focus, active states.
Styleguide creation process

4. Add layout last and put the components into
   place. Each layout could be presented as a
   separate document.

5. Document your coding process: naming
   conventions and the thinking behind
   decisions of grouping, classifying
   components, etc.
So everyone can access the
treasures




                         http://www.flickr.com/photos/lecercle/514344657/
With the knowledge of The
Masters
The code has been improved!




                        http://www.flickr.com/photos/clspeace/2143292403/
Srsly!



         Start   Finish


   7500 2250
And made Poësia…




                   http://www.flickr.com/photos/drobnikm/525835032/
(You know how I’m going to end
this)




                         http://www.flickr.com/photos/sonialuna/2942020058/
Character list and Resources
The Marcot




…is Ethan Marcotte, the creator and author
of Responsive Web Design (RWD)
http://ethanmarcotte.com/
twitter.com/beep
                                        http://www.flickr.com/photos/localcelebrity/7907876246/
The Dry Wind




…is Jeremy Clarke, the developer of DRY
CSS.
http://simianuprising.com/
twitter.com/jeremyclarke
The Ninja




…is Nicole Sullivan, the creatrice of Object
Oriented CSS (OOCSS)
http://www.stubbornella.org/
twitter.com/stubbornella
                                           http://www.flickr.com/photos/localcelebrity/6025912453/
The Lumberjack




…is Jonathan Snook, the creator and
author of Scalable and Modular CSS
(SMACSS)
http://snook.ca/ & http://smacss.com
twitter.com/snookca
                                       http://www.flickr.com/photos/splat/3742596419/
The Brit




…is Andy Hume, the creator of CSS for
Grown Ups (I like to shorten this to CFGU).
http://andyhume.net
twitter.com/
                                         http://www.flickr.com/photos/angryamoeba/4674320039/
Djinn




…is Jennifer Dixon, front-end developer
extraordinaire
http://jdcoding.com
twitter.com/jenniration
Illustrations by




Lorenzo Grandi
LorenzoGrandi.it
My books




The CSS Detective          Smashing Books #3             InterAct With
Guide                      &                             Web Standards:
                           #3 1/3
CSSDetectiveGuide.co                                     InterActWithWebStandards.co
m                                                        m
twitter.com/cssdetective   SmashingBook.com              twitter.com/waspinteract

                           My chapter:
                           “Storytelling in Webdesign”
And I am…




DeniseJacobs.com
denise@denisejacobs.com
twitter.com/denisejacobs
Now I really mean it!
Thank You!




             http://www.flickr.com/photos/theredproject/3302110152/

Weitere ähnliche Inhalte

Was ist angesagt?

Object-Oriented CSS 從 OOCSS, SMACSS, BEM 到 AMCSS
Object-Oriented CSS 從 OOCSS, SMACSS, BEM 到 AMCSSObject-Oriented CSS 從 OOCSS, SMACSS, BEM 到 AMCSS
Object-Oriented CSS 從 OOCSS, SMACSS, BEM 到 AMCSSLi-Wei Lu
 
The Fast And The Fabulous
The Fast And The FabulousThe Fast And The Fabulous
The Fast And The FabulousNicole Sullivan
 
About Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSAbout Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSNaga Harish M
 
OOCSS Lightening Talk
OOCSS Lightening TalkOOCSS Lightening Talk
OOCSS Lightening TalkJulie Cameron
 
Modular HTML, CSS, & JS Workshop
Modular HTML, CSS, & JS WorkshopModular HTML, CSS, & JS Workshop
Modular HTML, CSS, & JS WorkshopShay Howe
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS MethodologyZohar Arad
 
Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3Doris Chen
 
Rock Solid CSS Architecture
Rock Solid CSS ArchitectureRock Solid CSS Architecture
Rock Solid CSS ArchitectureJohn Need
 
Three quick accessibility tips for HTML5
Three quick accessibility tips for HTML5Three quick accessibility tips for HTML5
Three quick accessibility tips for HTML5Russ Weakley
 
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...Nicole Sullivan
 
Web front end development introduction to html css and javascript
Web front end development introduction to html css and javascriptWeb front end development introduction to html css and javascript
Web front end development introduction to html css and javascriptMarc Huang
 

Was ist angesagt? (20)

Object-Oriented CSS 從 OOCSS, SMACSS, BEM 到 AMCSS
Object-Oriented CSS 從 OOCSS, SMACSS, BEM 到 AMCSSObject-Oriented CSS 從 OOCSS, SMACSS, BEM 到 AMCSS
Object-Oriented CSS 從 OOCSS, SMACSS, BEM 到 AMCSS
 
The Fast And The Fabulous
The Fast And The FabulousThe Fast And The Fabulous
The Fast And The Fabulous
 
About Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSAbout Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JS
 
OOCSS Lightening Talk
OOCSS Lightening TalkOOCSS Lightening Talk
OOCSS Lightening Talk
 
Modular HTML, CSS, & JS Workshop
Modular HTML, CSS, & JS WorkshopModular HTML, CSS, & JS Workshop
Modular HTML, CSS, & JS Workshop
 
BEM it!
BEM it!BEM it!
BEM it!
 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
 
Material design
Material designMaterial design
Material design
 
Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3
 
Rock Solid CSS Architecture
Rock Solid CSS ArchitectureRock Solid CSS Architecture
Rock Solid CSS Architecture
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 
Three quick accessibility tips for HTML5
Three quick accessibility tips for HTML5Three quick accessibility tips for HTML5
Three quick accessibility tips for HTML5
 
Intro to CSS3
Intro to CSS3Intro to CSS3
Intro to CSS3
 
Css.html
Css.htmlCss.html
Css.html
 
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective,  Ajax ...
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
 
Web front end development introduction to html css and javascript
Web front end development introduction to html css and javascriptWeb front end development introduction to html css and javascript
Web front end development introduction to html css and javascript
 
Bootstrap 5 ppt
Bootstrap 5 pptBootstrap 5 ppt
Bootstrap 5 ppt
 
Taming CSS Selectors
Taming CSS SelectorsTaming CSS Selectors
Taming CSS Selectors
 
Css3
Css3Css3
Css3
 

Andere mochten auch

지성봉 - WAI-ARIA 실전 공략 [WSConf. Seoul 2016/2017]
지성봉 - WAI-ARIA 실전 공략 [WSConf. Seoul 2016/2017]지성봉 - WAI-ARIA 실전 공략 [WSConf. Seoul 2016/2017]
지성봉 - WAI-ARIA 실전 공략 [WSConf. Seoul 2016/2017]WSConf.
 
김태훈 - Google AMP는 어떻게 빠른 성능을 내나 [WSConf. Seoul 2016/2017]
김태훈 - Google AMP는 어떻게 빠른 성능을 내나 [WSConf. Seoul 2016/2017]김태훈 - Google AMP는 어떻게 빠른 성능을 내나 [WSConf. Seoul 2016/2017]
김태훈 - Google AMP는 어떻게 빠른 성능을 내나 [WSConf. Seoul 2016/2017]WSConf.
 
안형우 - 유지보수하기 쉬운 CSS 전략 [WSConf. Seoul 2016/2017]
안형우 - 유지보수하기 쉬운 CSS 전략 [WSConf. Seoul 2016/2017]안형우 - 유지보수하기 쉬운 CSS 전략 [WSConf. Seoul 2016/2017]
안형우 - 유지보수하기 쉬운 CSS 전략 [WSConf. Seoul 2016/2017]WSConf.
 
윤원진 - 반응형웹디자인(RWD)을 위한 넓고 얕은 지식 [WSConf. Seoul 2016]
윤원진 - 반응형웹디자인(RWD)을 위한 넓고 얕은 지식 [WSConf. Seoul 2016]윤원진 - 반응형웹디자인(RWD)을 위한 넓고 얕은 지식 [WSConf. Seoul 2016]
윤원진 - 반응형웹디자인(RWD)을 위한 넓고 얕은 지식 [WSConf. Seoul 2016]WSConf.
 
Creating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchCreating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchRuss Weakley
 
정찬명 - CSS Selectors in HTML [WSConf. Seoul 2016/2017]
정찬명 - CSS Selectors in HTML [WSConf. Seoul 2016/2017]정찬명 - CSS Selectors in HTML [WSConf. Seoul 2016/2017]
정찬명 - CSS Selectors in HTML [WSConf. Seoul 2016/2017]WSConf.
 
이환 - 이미지는 마크업의 반이다. [WSConf. Seoul 2016/2017]
이환 - 이미지는 마크업의 반이다. [WSConf. Seoul 2016/2017]이환 - 이미지는 마크업의 반이다. [WSConf. Seoul 2016/2017]
이환 - 이미지는 마크업의 반이다. [WSConf. Seoul 2016/2017]WSConf.
 
김영욱 - Microsoft Bot Framework [WSConf. Seoul 2017]
김영욱 - Microsoft Bot Framework [WSConf. Seoul 2017]김영욱 - Microsoft Bot Framework [WSConf. Seoul 2017]
김영욱 - Microsoft Bot Framework [WSConf. Seoul 2017]WSConf.
 

Andere mochten auch (8)

지성봉 - WAI-ARIA 실전 공략 [WSConf. Seoul 2016/2017]
지성봉 - WAI-ARIA 실전 공략 [WSConf. Seoul 2016/2017]지성봉 - WAI-ARIA 실전 공략 [WSConf. Seoul 2016/2017]
지성봉 - WAI-ARIA 실전 공략 [WSConf. Seoul 2016/2017]
 
김태훈 - Google AMP는 어떻게 빠른 성능을 내나 [WSConf. Seoul 2016/2017]
김태훈 - Google AMP는 어떻게 빠른 성능을 내나 [WSConf. Seoul 2016/2017]김태훈 - Google AMP는 어떻게 빠른 성능을 내나 [WSConf. Seoul 2016/2017]
김태훈 - Google AMP는 어떻게 빠른 성능을 내나 [WSConf. Seoul 2016/2017]
 
안형우 - 유지보수하기 쉬운 CSS 전략 [WSConf. Seoul 2016/2017]
안형우 - 유지보수하기 쉬운 CSS 전략 [WSConf. Seoul 2016/2017]안형우 - 유지보수하기 쉬운 CSS 전략 [WSConf. Seoul 2016/2017]
안형우 - 유지보수하기 쉬운 CSS 전략 [WSConf. Seoul 2016/2017]
 
윤원진 - 반응형웹디자인(RWD)을 위한 넓고 얕은 지식 [WSConf. Seoul 2016]
윤원진 - 반응형웹디자인(RWD)을 위한 넓고 얕은 지식 [WSConf. Seoul 2016]윤원진 - 반응형웹디자인(RWD)을 위한 넓고 얕은 지식 [WSConf. Seoul 2016]
윤원진 - 반응형웹디자인(RWD)을 위한 넓고 얕은 지식 [WSConf. Seoul 2016]
 
Creating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchCreating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off Switch
 
정찬명 - CSS Selectors in HTML [WSConf. Seoul 2016/2017]
정찬명 - CSS Selectors in HTML [WSConf. Seoul 2016/2017]정찬명 - CSS Selectors in HTML [WSConf. Seoul 2016/2017]
정찬명 - CSS Selectors in HTML [WSConf. Seoul 2016/2017]
 
이환 - 이미지는 마크업의 반이다. [WSConf. Seoul 2016/2017]
이환 - 이미지는 마크업의 반이다. [WSConf. Seoul 2016/2017]이환 - 이미지는 마크업의 반이다. [WSConf. Seoul 2016/2017]
이환 - 이미지는 마크업의 반이다. [WSConf. Seoul 2016/2017]
 
김영욱 - Microsoft Bot Framework [WSConf. Seoul 2017]
김영욱 - Microsoft Bot Framework [WSConf. Seoul 2017]김영욱 - Microsoft Bot Framework [WSConf. Seoul 2017]
김영욱 - Microsoft Bot Framework [WSConf. Seoul 2017]
 

Ähnlich wie Scalable and Modular CSS FTW!

Scalable and Modular CSS FTW!
Scalable and Modular CSS FTW!Scalable and Modular CSS FTW!
Scalable and Modular CSS FTW!Denise Jacobs
 
960 grid psd
960 grid psd960 grid psd
960 grid psdRaju Nag
 
The Age of Responsive Design
The Age of Responsive DesignThe Age of Responsive Design
The Age of Responsive DesignDenise Jacobs
 
Let There Be Peace On CSS - Cristiano Rastelli - Codemotion Amsterdam 2018
Let There Be Peace On CSS - Cristiano Rastelli - Codemotion Amsterdam 2018Let There Be Peace On CSS - Cristiano Rastelli - Codemotion Amsterdam 2018
Let There Be Peace On CSS - Cristiano Rastelli - Codemotion Amsterdam 2018Codemotion
 
The Importance of Storytelling in Web Design, WordCamp Miami 2013
The Importance of Storytelling in Web Design, WordCamp Miami 2013The Importance of Storytelling in Web Design, WordCamp Miami 2013
The Importance of Storytelling in Web Design, WordCamp Miami 2013Denise Jacobs
 
CSS3: stay tuned for style
CSS3: stay tuned for styleCSS3: stay tuned for style
CSS3: stay tuned for styleChris Mills
 
The Art Of Indexing
The Art Of IndexingThe Art Of Indexing
The Art Of IndexingKenSimmons
 
Austin cassandra meetup
Austin cassandra meetupAustin cassandra meetup
Austin cassandra meetupgdusbabek
 
Hacking the Creative Brain - Devoxx Belgium, 2014
Hacking the Creative Brain -  Devoxx Belgium, 2014Hacking the Creative Brain -  Devoxx Belgium, 2014
Hacking the Creative Brain - Devoxx Belgium, 2014Denise Jacobs
 
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)Christopher Schmitt
 
Creativity (R)Evolution - ThatConference 2013
Creativity (R)Evolution - ThatConference 2013Creativity (R)Evolution - ThatConference 2013
Creativity (R)Evolution - ThatConference 2013Denise Jacobs
 
Advanced CSS Troubleshooting
Advanced CSS TroubleshootingAdvanced CSS Troubleshooting
Advanced CSS TroubleshootingDenise Jacobs
 
Creating an e zine
Creating an e zineCreating an e zine
Creating an e zineAiden Yeh
 

Ähnlich wie Scalable and Modular CSS FTW! (20)

Scalable and Modular CSS FTW!
Scalable and Modular CSS FTW!Scalable and Modular CSS FTW!
Scalable and Modular CSS FTW!
 
Orchestrating Content
Orchestrating ContentOrchestrating Content
Orchestrating Content
 
960 grid psd
960 grid psd960 grid psd
960 grid psd
 
The Age of Responsive Design
The Age of Responsive DesignThe Age of Responsive Design
The Age of Responsive Design
 
Let There Be Peace On CSS - Cristiano Rastelli - Codemotion Amsterdam 2018
Let There Be Peace On CSS - Cristiano Rastelli - Codemotion Amsterdam 2018Let There Be Peace On CSS - Cristiano Rastelli - Codemotion Amsterdam 2018
Let There Be Peace On CSS - Cristiano Rastelli - Codemotion Amsterdam 2018
 
The Importance of Storytelling in Web Design, WordCamp Miami 2013
The Importance of Storytelling in Web Design, WordCamp Miami 2013The Importance of Storytelling in Web Design, WordCamp Miami 2013
The Importance of Storytelling in Web Design, WordCamp Miami 2013
 
CSS3: stay tuned for style
CSS3: stay tuned for styleCSS3: stay tuned for style
CSS3: stay tuned for style
 
The Art Of Indexing
The Art Of IndexingThe Art Of Indexing
The Art Of Indexing
 
NCompass Live: CSS: A Brief Introduction
NCompass Live: CSS: A Brief Introduction NCompass Live: CSS: A Brief Introduction
NCompass Live: CSS: A Brief Introduction
 
SOLID principles
SOLID principlesSOLID principles
SOLID principles
 
Refresh OKC
Refresh OKCRefresh OKC
Refresh OKC
 
Austin cassandra meetup
Austin cassandra meetupAustin cassandra meetup
Austin cassandra meetup
 
Hacking the Creative Brain - Devoxx Belgium, 2014
Hacking the Creative Brain -  Devoxx Belgium, 2014Hacking the Creative Brain -  Devoxx Belgium, 2014
Hacking the Creative Brain - Devoxx Belgium, 2014
 
What is Modular CSS?
What is Modular CSS?What is Modular CSS?
What is Modular CSS?
 
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)
 
Soc 354
Soc 354Soc 354
Soc 354
 
Creativity (R)Evolution - ThatConference 2013
Creativity (R)Evolution - ThatConference 2013Creativity (R)Evolution - ThatConference 2013
Creativity (R)Evolution - ThatConference 2013
 
Advanced CSS Troubleshooting
Advanced CSS TroubleshootingAdvanced CSS Troubleshooting
Advanced CSS Troubleshooting
 
MN ARLD Day 2012
MN ARLD Day 2012MN ARLD Day 2012
MN ARLD Day 2012
 
Creating an e zine
Creating an e zineCreating an e zine
Creating an e zine
 

Mehr von FITC

Cut it up
Cut it upCut it up
Cut it upFITC
 
Designing for Digital Health
Designing for Digital HealthDesigning for Digital Health
Designing for Digital HealthFITC
 
Profiling JavaScript Performance
Profiling JavaScript PerformanceProfiling JavaScript Performance
Profiling JavaScript PerformanceFITC
 
Surviving Your Tech Stack
Surviving Your Tech StackSurviving Your Tech Stack
Surviving Your Tech StackFITC
 
How to Pitch Your First AR Project
How to Pitch Your First AR ProjectHow to Pitch Your First AR Project
How to Pitch Your First AR ProjectFITC
 
Start by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the AnswerStart by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the AnswerFITC
 
Cocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s StoryCocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s StoryFITC
 
Everyday Innovation
Everyday InnovationEveryday Innovation
Everyday InnovationFITC
 
HyperLight Websites
HyperLight WebsitesHyperLight Websites
HyperLight WebsitesFITC
 
Everything is Terrifying
Everything is TerrifyingEverything is Terrifying
Everything is TerrifyingFITC
 
Post-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanPost-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanFITC
 
The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)FITC
 
East of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR GameEast of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR GameFITC
 
Creating a Proactive Healthcare System
Creating a Proactive Healthcare SystemCreating a Proactive Healthcare System
Creating a Proactive Healthcare SystemFITC
 
World Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product DesignWorld Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product DesignFITC
 
The Power of Now
The Power of NowThe Power of Now
The Power of NowFITC
 
High Performance PWAs
High Performance PWAsHigh Performance PWAs
High Performance PWAsFITC
 
Rise of the JAMstack
Rise of the JAMstackRise of the JAMstack
Rise of the JAMstackFITC
 
From Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self DiscoveryFrom Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self DiscoveryFITC
 
Projects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time ForProjects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time ForFITC
 

Mehr von FITC (20)

Cut it up
Cut it upCut it up
Cut it up
 
Designing for Digital Health
Designing for Digital HealthDesigning for Digital Health
Designing for Digital Health
 
Profiling JavaScript Performance
Profiling JavaScript PerformanceProfiling JavaScript Performance
Profiling JavaScript Performance
 
Surviving Your Tech Stack
Surviving Your Tech StackSurviving Your Tech Stack
Surviving Your Tech Stack
 
How to Pitch Your First AR Project
How to Pitch Your First AR ProjectHow to Pitch Your First AR Project
How to Pitch Your First AR Project
 
Start by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the AnswerStart by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the Answer
 
Cocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s StoryCocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s Story
 
Everyday Innovation
Everyday InnovationEveryday Innovation
Everyday Innovation
 
HyperLight Websites
HyperLight WebsitesHyperLight Websites
HyperLight Websites
 
Everything is Terrifying
Everything is TerrifyingEverything is Terrifying
Everything is Terrifying
 
Post-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanPost-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future Human
 
The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)
 
East of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR GameEast of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR Game
 
Creating a Proactive Healthcare System
Creating a Proactive Healthcare SystemCreating a Proactive Healthcare System
Creating a Proactive Healthcare System
 
World Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product DesignWorld Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product Design
 
The Power of Now
The Power of NowThe Power of Now
The Power of Now
 
High Performance PWAs
High Performance PWAsHigh Performance PWAs
High Performance PWAs
 
Rise of the JAMstack
Rise of the JAMstackRise of the JAMstack
Rise of the JAMstack
 
From Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self DiscoveryFrom Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self Discovery
 
Projects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time ForProjects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time For
 

Scalable and Modular CSS FTW!

  • 1. Scalable and Modular CSS FTW! The Legend of the Birth of MetaCoax / * Denise R. Jacobs Future. Innovation. Technology. Creativity. Amsterdam, Netherlands 18 February 2013 */
  • 2. Tweeting tall tales I am: @denisejacobs This fine event is: @fitc #FITCAms And I’m telling the tale of: #metacoax
  • 3. And tell stories about CSS
  • 4. I like to make stuff
  • 5. The Legend of the Birth of MetaCoax chapter 1 Problems in Poësia chapter 2 The Teachings of the Masters chapter 3 Insights and Epiphanies chapter 4 Ousting Selector Evil chapter 5 Triumph!
  • 7. You know how all stories start…
  • 8. There was a Kingdom called Poësia http://www.flickr.com/photos/drobnikm/525835032/
  • 10. On the surface, all was fine… http://www.flickr.com/photos/trodel/3801987960/
  • 11. Behind the city’s walls… http://www.flickr.com/photos/kathrynvjones/3737219448/
  • 12. It was a nightmare of dis- organization http://www.flickr.com/photos/torley/4096277982/
  • 13. Top architects and designers http://www.flickr.com/photos/massgovernor/7345462040/
  • 14. Who hired builders http://www.flickr.com/photos/8533266@N04/4457182603/
  • 15. Some believed in mastery… http://www.flickr.com/photos/statuelibrtynps/6276757947/
  • 16. Others were not http://www.flickr.com/photos/anotherjesse/243020629/
  • 17. Put together with whatever was handy http://www.flickr.com/photos/laughingsquid/142398084
  • 18. Shabby new structures http://www.flickr.com/photos/cbnsp/6605969807/
  • 19. They didn’t start off evil http://www.flickr.com/photos/dr_john2005/3934871670/
  • 20. …but they slowly became so over time http://www.flickr.com/photos/dr_john2005/3935163348/
  • 21. Follow suit and try to fit in
  • 22. Fight by trying to become !important http://www.flickr.com/photos/stuckincustoms/6199442617/
  • 23. He sent out his two most trusted aides… http://www.flickr.com/photos/bbsc30/168832715/
  • 24. They traveled far and wide… http://www.flickr.com/photos/annegirl/435308460/
  • 25. And found the prophet Marcot http://www.flickr.com/photos/axsdeny/2607122395/
  • 26. The gospel of Responsive
  • 27. He spoke of a championne http://www.flickr.com/photos/44085287@N05/4055807492/
  • 28. They traveled south to Mijami… Photo: Denise Jacobs
  • 29. To find Djieh and Djinn!
  • 30. Chapter 2 The Teachings of the Masters
  • 31. They went deep into the canyons http://www.flickr.com/photos/gods-art/6622668251/
  • 32. The Dry Wind appeared to them http://www.flickr.com/photos/gods-art/6622669139/
  • 34. DRY CSS “Don’t Repeat Yourself” Never repeat a style/property definition…ever.
  • 35. DRY CSS: Thinking When looking at making a style declaration for a selector, always have an answer to the question "Why isn’t this part of a group?” Then figure out how to make it one.
  • 36. DRY CSS: Approach Groups define shared properties. Group selectors with shared properties, rather than defining them separately. While the groups have many selectors, each property/value pair is defined only once.
  • 37. DRY CSS: How • Name the groups based on their role in the design • Use the name as an ID at the top of the list and a class at the bottom • Group selectors that share properties above the properties they share
  • 38. For example #LIGHT-WHITE-BACKGROUND, .translation, .entry .wp-caption, #full-article .entry img, .recent-comment .comment-text, .roundup h3, .post-header-sharing, #post-categories td.label, #post-archive roundup h3, .subscription-manager ol, .light-white-background { background-color: #fff; border-color: #ccc; }
  • 39.
  • 40. The Ninja http://www.flickr.com/photos/branditressler/2912153888/
  • 43. Outcome CSS bytes/page HTML bytes/page 19% 44% decrease decrease
  • 44. OOCSS: Signs you need it • Large number of floats = bad grid • Large number of margins = you need a reset css • Large number of font-size & !important = cascade is not being leveraged
  • 45. OOCSS: The Gist • Employ DRY • Separate structure and presentation • Modularize
  • 46. OOCSS: Do’s • Use CSS grids • Keep selector chains as short as possible • Give rules the same weight/strength • Use <hr> as a page section delimiter • Style classes rather than elements
  • 47. OOCSS: Don’ts • Avoid attaching classes to elements • Avoid using IDs as styling hooks, use them for JS hooks and page anchors • Avoid the descendent selector • Don’t over-semanticize class names • Avoid classnames that are related to the appearance of the style
  • 48. OOCSS: The process 1. Determine the site-wide “legos” (ie, reusable pieces) 2. Separate – Container and Content – Structure and Skin – Contour and Background – Objects and Mix-ins 3. Mix and match container and content objects to achieve high performance design. 4. Skin for visual difference
  • 49. OOCSS: The Media Module http://www.stubbornella.org/content/2010/06/25/the-media-object-saves-hundreds-of-lines-of-code/
  • 50. OOCSS: The Media Module <!-- media --> <div class="media"> <img class="fixedMedia" src="myImg.png" /> <div class="text"> ... </div> </div>
  • 51. OOCSS: The Media Module /* ====== media ====== */ .media {margin:10px;} .media, .bd {overflow:hidden; _overflow:visible; zoom:1;} .media .img {float:left; margin-right: 10px;} .media .img img{display:block;} .media .imgExt{float:right; margin-left: 10px;}
  • 52. The Lumberjack http://www.flickr.com/photos/stikeymo/308546507/
  • 53. SMACSS Scalable and Modular Architecture for CSS https://smacss.com/
  • 54. SMACSS: Style categories • Base • Layout • Module • State • Theme
  • 55. SMACSS: Curb your enthusiasm Selectors should be “shallow” instead of “deep” Strive for the shallowest possible.
  • 56. SMACSS: Deep selector div#childrens-footer div#col2.column div.bestRight p.bestTitle
  • 58. SMACSS: Shallow selectors 101 • Avoid tag selectors for common elements unless completely predictable. • Use class names as the right-most (key) selector • Use the child selector
  • 59. SMACSS: On “classitis” You’re better off adding classes to the elements in question and repeating the class in the HTML than having overly-specific styles. Instead of being classitis, using multiple classes clarifies intent and increases the semantics of elements in question.
  • 60. SMACSS: Module candidates • Nav bars • Carousels • Dialogs • Widgets • Tables • icons
  • 61. SMACSS: States State changes can be notated by class names like .is-active .is-collapsed .btn-pressed
  • 62. SMACSS: What’s in a name? an example module: .example a callout module: .callout a callout module with a collapsed state: .callout.is-collapsed
  • 63. SMACSS: Words of Wisdom “Constrain, but don’t choke. Consider selector performance, but don’t waste too much time on it.”
  • 64. The Brit http://www.flickr.com/photos/31363949@N02/6958447097/
  • 65. CSS For Grown Ups https://speakerdeck.com/u/andyhume/p/css-for- grown-ups-maturing-best-practises http://schedule.sxsw.com/2012/events/event_IA P9410 (audio)
  • 66. He lived his own nightmare http://www.flickr.com/photos/djrue/4835062638/
  • 67. CSS For Grown Ups Don’t style pages, style modules. Have a style module library that you can reuse.
  • 68. CSS For Grown Ups Think of your styles as being in layers: • document – from HTML code, element selectors • base styles • module styles • layout styles
  • 69. CSS For Grown Ups Easy determination: A tag as part of the selector = a document style If you create a class for it, you release it from the tag and make it a module style.
  • 70. CSS For Grown Ups: Don’t …make modules variations based on IDs, base them on classes instead #sidebar .promo-box = bad .promo-box { ... } = okay .promo-box-light { ... } = better!
  • 71. CSS For Grown Ups: Modules .promo-box Related/sub-styles: module’s name extended with two dashes .promo-box--eco javascript class prefixed with js: .js-login
  • 72. CSS For Grown Ups: Typography .h-headline .h-subheadline .h-byline .h-promo
  • 73. CSS For Grown Ups: Helpers “Surgical layout helpers” which are things like paddings, margins, and gutters as separate classes. .margin-top {margin-top: 1em;}
  • 75. The Masters all speak the same truths http://www.flickr.com/photos/s4xton/2425718415/
  • 76. Their teachings • Ids? Not so much. • Classes? Aww yeah! • With selectors, less is more • Get your module on • Naming conventions? !Important
  • 77. Can be simplified to this: • Structure and Inform • Reduce • Recycle and Reuse
  • 78. Structure and Inform http://www.flickr.com/photos/trvance/3138749670/
  • 79. Structure and Inform • Utilize a naming convention to establish structure and meaning • Categorize styles in the document or into multiple documents • Employ grids for consistent page structure
  • 81. Reduce • Eliminate inline styles • Write the shortest chain of elements possible in selectors • Drop elements: as qualifiers and selectors • Choose classes over ids
  • 82. Recycle & Reuse http://www.flickr.com/photos/epsos/5575089139/
  • 83. Recycle & Reuse • Leverage the cascade better to cut down on redundant style declarations • Modularize page components to reuse throughout site • Extend modules through subclassing
  • 84. They figured out the key! http://www.flickr.com/photos/karent/3673326282/
  • 85. What do you do when you build? http://www.flickr.com/photos/mdave/2878687949/
  • 86. Exactly! http://www.flickr.com/photos/chriscoyier/5269340772/
  • 87. What should we call it? Hmmm… measure twice, cut once css  mtco css  meta coa css  MetaCoax!
  • 88. And thus, MetaCoax was born! { Measure twice: cut once; }
  • 89. Djiejh and Djinn went to Poësia… http://www.flickr.com/photos/trodel/3801987960/
  • 91. Institute change in 3 phases .flickr.com/photos/boklm/486646798/
  • 92. (1) Initial phase • Optimize selectors • Reduce the redundant
  • 93. Optimize Selectors • Eliminate qualifier selectors [oocss] • Eliminate the middleman • Have the shortest chain possible [oocss, smacss]
  • 94. Qualified selectors div# div. 1259 836
  • 95. Eliminate qualifier selectors Selectors like div#widget-nav div#widget-nav-slider ul li div.name span Could easily be simplified into #widget-nav-slider .name span with the exact same outcome.
  • 96. Eliminate the middleman If you must use a descendent selector, then eliminate all unnecessary elements in it: .widget li a would become .widget a
  • 97. Have the shortest chain possible For example, instead of #toc > LI > A it’s better to create a class, such as .toc-anchor
  • 98. Reduce the Redundant • Leverage the cascade by relying on inheritance [oocss] • Review, revise and reduce !important [oocss, smacss]
  • 99. Leverage the cascade with inheritance color font-family font-size font-style font-variant font-weight font line-height list-style-image list-style-position list-style-type list-style text-align text-indent text-transform visibility white-space word-spacing
  • 100. Not using the cascade font font-size 100 112
  • 101. Review, revise and reduce !important If there are a lot of styles that are !important then…
  • 102. UR DOIN’ IT WRONG
  • 103. For example… !important 126
  • 104. (2) Intermediate phase • Clear the cruft • Create preliminary portable styles [cfgu] • Begin instituting modules based on design patterns [oocss, smacss, cfgu] • Institute a Grid [oocss]
  • 105. Clear the cruft • Eliminate inline styles & decrease use of <span> • Eliminate styles that rely on qualifiers high in the DOM [oocss] • Use classnames as key selector [smacss] • Create preliminary portable styles [cfgu]
  • 106. Eliminate styles that rely on qualifiers high in the DOM body.video div#lowercontent div.children.videoitem.hover a.title { background: #bc5b29; color: #fff !important; text-decoration: none; }
  • 107. Too high in the DOM body# 936
  • 108. Create preliminary portable styles • Typographic classes for headings, etc.[cfgu] • Surgical layout helpers [cfgu]
  • 109. Is surgery necessary? margin-top margin-bottom 189 112
  • 110. Institute a Grid • Use CSS3 box-sizing • Make the grid and images fluid
  • 111. Bad grid width margin 327 738
  • 112. Good grid .l-col-1-1 {float:none;} .l-col-1-2 {width:50%; *width:43%; } .l-col-1-3 {width:33.33333%; *width:32.33333%;} .l-col-2-3 {width:66.66666%; *width:65.66666%;} .l-col-1-4 {width:25%; *width:23%; } .l-col-3-4 {width:75%; *width:72%;} .l-col-1-5 {width:20%; *width:19%;} .l-col-2-5 {width:40%; *width:39%;} .l-col-3-5 {width:60%; *width:59%;} .l-col-4-5 {width:80%; *width:79%;} .l-col-1-6 {width:16.6%; *width:15.6%;}
  • 113. Make the grid and images fluid img { max-width: 100%; height: auto; }
  • 114. (3) Advanced phase • Continue modularizing page elements [ocss, smacss, cfgu] • Continue cleaning-up selectors and styles • Separate CSS files by category [smacss]
  • 116. Structure http://www.flickr.com/photos/joebehr/6349047969/
  • 117. Inbred selectors banished http://i31.photobucket.com/albums/c351/Rasey07/twins.jpg
  • 119. Ready for a responsive future http://www.flickr.com/photos/digitalfrance/98314057/
  • 120. New best practices http://www.flickr.com/photos/torley/2761300969/
  • 121. Reset with Normalize.css http://necolas.github.com/normalize.css/
  • 122. Use a better Clearfix Still using this? <div class="clear"></div> … .clear { clear: both; }
  • 123. The New Clearfix /* For modern browsers */ .cf:before, .cf:after { content:""; display: table; } .cf:after { clear: both;} /* For IE 6/7 (trigger hasLayout) */ .cf { *zoom:1; }
  • 124. And a better Divider Seriously? <div class="divider"></div> … div.divider { border-top: 1px solid #ABAA9A; clear: both; }
  • 126. …And Image replacement .hide-text { text-indent: 100%; white-space: nowrap; overflow: hidden; }
  • 127. Use an icon element Instead of this: <li class="favorite"> <span class="icon favorite"></span> <span id="favorite-poem-insert-point" class="favorite"></span> </li>
  • 128. Use an icon element Do this: <p><i class="icon icon-comment"></i>23 comments</p> ... .icon {background-image: url( sprites.png ); } .icon-comments {background-position: 0 -30px; }
  • 130. Just revamping the code isn’t enough… “Even the cleanest code gets ruined by the first non-expert to touch it.” - Nicole Sullivan, The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective
  • 131. Website styleguide http://www.flickr.com/photos/littlemad/5729783584/
  • 132. Styleguide Creation Process 1. Determine the unique elements and components that will be in the styleguide. Also notate the main colors for text, header, links, and buttons. 2. Start styling the core elements of the pages: headings, links, tables, blockquotes, unordered and ordered lists, and forms. 3. Style the components that override the base styles, such as search boxes, breadcrumb navigation, themed buttons, and variations in modules. Include interaction styles: hover, focus, active states.
  • 133. Styleguide creation process 4. Add layout last and put the components into place. Each layout could be presented as a separate document. 5. Document your coding process: naming conventions and the thinking behind decisions of grouping, classifying components, etc.
  • 134. So everyone can access the treasures http://www.flickr.com/photos/lecercle/514344657/
  • 135. With the knowledge of The Masters
  • 136. The code has been improved! http://www.flickr.com/photos/clspeace/2143292403/
  • 137. Srsly! Start Finish 7500 2250
  • 138. And made Poësia… http://www.flickr.com/photos/drobnikm/525835032/
  • 139. (You know how I’m going to end this) http://www.flickr.com/photos/sonialuna/2942020058/
  • 140. Character list and Resources
  • 141. The Marcot …is Ethan Marcotte, the creator and author of Responsive Web Design (RWD) http://ethanmarcotte.com/ twitter.com/beep http://www.flickr.com/photos/localcelebrity/7907876246/
  • 142. The Dry Wind …is Jeremy Clarke, the developer of DRY CSS. http://simianuprising.com/ twitter.com/jeremyclarke
  • 143. The Ninja …is Nicole Sullivan, the creatrice of Object Oriented CSS (OOCSS) http://www.stubbornella.org/ twitter.com/stubbornella http://www.flickr.com/photos/localcelebrity/6025912453/
  • 144. The Lumberjack …is Jonathan Snook, the creator and author of Scalable and Modular CSS (SMACSS) http://snook.ca/ & http://smacss.com twitter.com/snookca http://www.flickr.com/photos/splat/3742596419/
  • 145. The Brit …is Andy Hume, the creator of CSS for Grown Ups (I like to shorten this to CFGU). http://andyhume.net twitter.com/ http://www.flickr.com/photos/angryamoeba/4674320039/
  • 146. Djinn …is Jennifer Dixon, front-end developer extraordinaire http://jdcoding.com twitter.com/jenniration
  • 148. My books The CSS Detective Smashing Books #3 InterAct With Guide & Web Standards: #3 1/3 CSSDetectiveGuide.co InterActWithWebStandards.co m m twitter.com/cssdetective SmashingBook.com twitter.com/waspinteract My chapter: “Storytelling in Webdesign”
  • 150. Now I really mean it!
  • 151. Thank You! http://www.flickr.com/photos/theredproject/3302110152/

Hinweis der Redaktion

  1. In a land far away,
  2. Whose emperor was…
  3. …who was deeply troubled.
  4. On the surface, the kingdom looked as if it should with all of the necessary elements in place,
  5. While some of the builders believed in their craft/were concerned with the mastery of their craft and were committed to building structures that could scale and stand the test of time…
  6. Others were a rag-tag bunch…
  7. who would hastily build with whatever was handy,
  8. ending up with each new structures of selectors shabbily tacked on to the last.New builders came and went, so that ones being added to build the kingdom had no way of know the intentions of the builders before them.
  9. The structures of the selectors they created didn’t start off evil…
  10. But over time, they became more established and caused problems based on their position in the hierarchy.
  11. New selectors that came after them had to try to establish themselves by any means possible. So, no matter how ridiculous they looked, they would try to fit in by being long and unwieldy…
  12. Or fight by making themselves !importantHe’d heard tell that there were wise masters whose teachings could guide and provide structure to the work of the architects and builders, but half-crazed and feverish with the single-minded goal of seeing the kingdom to completion as they originally planned it, his hired design and building experts poo-pooed his suggestions and dismissed the legends relegating them to mere fantasy.
  13. Eric did not become ruler of his kingdom merely because of his impressive stature, regal bearing, and fine form. Being born of the stuff of myth himself, he knew that there had to be some verity in the legends. He sent out two of his most trusted aides Haliec and Vidad (whom he affectionately referred to at Scully and Mulder, because they were always actively seeking the truth) into the world to bring back a champion who could use this deep knowledge to bring order to the chaos within the kingdom.
  14. He spoke to them of a new responsive world, a world where a kingdom, if built correctly, could be accessed by all peoples through all ways and methods. No seeker of information would be turned away from the treasures that a kingdom contained. Even though this wasn’t the work of the masters that they initially sought, their eyes and hearts glowed at the possibility of taking their beloved kingdom to the next level by responding to the needs of their visitors. The wisdom of the Marcot renewed their lagging hope and passion to find a person who would banish the evil selectors from their kingdom once and for all, establish order, and prepare for a future of responsive greatness.
  15. The prophet Marcot saw the fire in their eyes and knew their hearts were pure and that they were true seekers. “There is one could help you,” he said. “Her name is Djiejh. I hear that she spreads the knowledge of the work of the masters. She may have answers for you.”
  16. They went south to the land of the sun and sea (Mijhami), They went south to the land of the sun and sea (Mijhami), where they found Djiejh and conveyed their king’s angst, frustration, and growing concern around the large and still growing ranks of evil selectors and their renegade rules that were behind the shiny façade of their kingdom. Djiejh heard them out, [and felt honor-bound to help them] and then spoke to them of the teachings of the Ninja. “We’ve heard of the Ninja!” they exclaimed! “She’s real? She’s not just a legend?”
  17. Djiejh spoke of the masters: The Ninja in the Area of the Bay, The Lumberjack, who hailed from the Great White North, and The Brit in the land of Londia. And finally, Djiejh related that calling upon the elemental The Dry Wind could help with the process and maintain order.
  18. The Ninja is one of my disciples and has taken my practices to another level. Seek her in the Area of the Bay.
  19. Large number of font-size = cascade is not being leveraged, also over-fussiness: few font sizes are readable - and small differences are not easily detectable.
  20. Employ DRY: endeavor to create and apply as many reusable pieces of code as possible.Separate structure and presentation: avoid coupling the CSS too tightly to presentation/displayModularize: find common elements and presentation and abstract these into reusable code (aka modules)
  21. Keep selector chains as short as possible: the browser can parse the CSS faster and it avoids specificity warsGive rules the same weight/strength so that you and mix and match them to extend an object through subclassingUse &lt;hr&gt; as a page section delimiter (instead of having top or bottom borders be part of an element)Style classes rather than elements
  22. Avoid the descendent selector (i.e. don’t use .sidebar h3)Avoid IDs as styling hooksAvoid attaching classes to elements in your stylesheet (i.e. don’t do div.header or h1.title)Don’t over-semanticize class names: overly semantic names prevent reuse, and classnames should convey useful information to developers.Avoid classnames that are related to the appearance of the styleAvoid using IDs for CSS styling, use them for JS hooks and page anchors predominantly
  23. Determine the site-wide “legos” (ie, reusable pieces), such as:Headings Lists (e.g. action list, external link list, product list, or feature list) Module headers and footers Grids Buttons Rounded corner boxes Tabs, Carousel, toggle blocks Objects and Mix-ins  Skin for visual differenceSkins/themes are the module’s presentation – how it looks. The goal is very predictable skins, values that can be easily calculated or measured.
  24. Like OOCSS, SMACSS is about identifying patterns in your design and codifying them, and has a great structure for naming classes in a meaningful and useful way
  25. Base - defaults: single element selectorsLayout – divides the page into sectionsModule – reusable, modular part of the design: callouts, sidebar sections, product lists, etc.State – ways to describe how the module or layout looks in a particular stateTheme – describe how modules or layouts might lookIn small projects, can all be in the same file. In larger projects, multiple files are recommended.
  26. Using a class is preferable, even if you think the element is going to stay predictable.
  27. You’re better off adding classes to the elements in question and repeating the class in the HTML (and potentially committing “classitis”) than having overly-specific styles. Instead of being classitis, using multiple classes clarifies intent and increases the semantics of elements in question.
  28. Some further methodologies with modules include avoiding conditional styling based on the module’s location on the page or on the website with sub-class module components, tying media-queries to the module or layout component instead of grouping them separately, which allows for the module to be kept together and for isolated testing of the module; and only using !important on state styles if necessary, but none others.
  29. In the naming convention for modules, include the name of the module itself.
  30. In Londia
  31. Worked at Clearleft and The Guardianwe’ve become obsessed with web standards to the degree that we strive to keep content and session separate to ridiculous lengths. In addition to web standards, managing complexity is an important factor to consider.  We need to optimize code for change, and let go of the idea that we will write HTML which we will never touch again, and do then just manage all of the presentation on the CSS side. In truth, we will always have to revamp the HTML along with the CSS.
  32. The goal is this: when creating selectors, be aware of whether they are document, base or module, and make an effort to keep them all modular level.
  33. But one WITH ids!
  34. The names of the modules again should be descriptive/semantic and not tied to location or appearance:
  35. Instead of styling headings by the elements, typographic classes are suggested, which can then be applied to h1-h6, p, dd, and any other tags, but the visual presentation will be the same:
  36. To handle presentation issues, it’s recommended to use helpersThe above style would be the style that you could add to whatever element needed it on the page, instead of wrapping that style into a component.
  37. Providing good information and organizing it is critical for clarity and understanding.
  38. Distilling even further, Djieh and Djinn discovered the essence – the key!
  39. Buoyed by their discoveries and new knowledge, they went to Poesia to implement their MetaCoax approach to taming the selectors that were running amok in the kingdom.
  40. The goal is to make the stylesheet a little more lightweight and easier to maintain and update with the minimum amount of time and effort investment. The focus is on giving structure and organization to the stylesheet, reducing redundancy and better reuse of styles, And optimizing the selectors
  41. Adopt a “3 or less” rule
  42. Reduces location dependencyIncrease portabilityReduces chances of selector breakageDecreases specificity/Avoids specificity warsPrevents over-use of !importantCan make code more forgiving
  43. Normalize.css “normalizes” the code to a common baseline rather than reseting the base styling for elements across all browsers.
  44. the Kellum method (http://www.zeldman.com/2012/03/01/replacing-the-9999px-hack-new-image-replacement/).Instead of hiding the text offscreen using the -9999px; hack (and creating a huge invisible box in the process), this new technique hides the text while leaving it accessible to screen readers.
  45. From 7500 lines to 2200 linesBetter in IE6 &amp; IE7
  46. …a better place for everyone – both visitors and builders alike.