SlideShare a Scribd company logo
TAMING SELECTORS
   sanity for our stylesheets
SIZE OF THE CSS FILE AND
 IMPLIED HTTP REQUESTS
   are the biggest factor for CSS performance
REFLOWS AND
RENDERING TIME
  are (much!) less important
DUPLICATION IS WORSE
  THAN STALE RULES
  because we have tools to deal with the later
DEFINE DEFAULT VALUES
   Don’t repeat this code in every object
#weatherModule h3{color:red;}
#tabs h3{color:blue}




 DEFINE DEFAULT VALUES
       Don’t repeat this code in every object
X
#weatherModule h3{color:red;}
#tabs h3{color:blue}




 DEFINE DEFAULT VALUES
       Don’t repeat this code in every object
X
#weatherModule h3{color:red;}
#tabs h3{color:blue}




 DEFINE DEFAULT VALUES
       Don’t repeat this code in every object
               h1,    .h1{...}
               h2,    .h2{...}
               h3,    .h3{...}
               h4,    .h4{...}
               h5,    .h5{...}
               h6,    .h6{...}
DEFINE STRUCTURE IN A
   SEPARATE CLASS
   Don’t repeat this code in every object
                                       block
                                          inner
                                                  hd




                                                  bd




                                                  ft
div.error{...}




           STYLE CLASSES
                 rather than elements
X
div.error{...}




           STYLE CLASSES
                 rather than elements


 .error{           most of the code goes here   }
X
  div.error{...}




             STYLE CLASSES
                   rather than elements


   .error{           most of the code goes here   }
div.error{                                        }
  p.error{                  exceptions only       }
 em.error{                                        }
div{...}
 ul{...}
 p{..}




AVOID STYLING ELEMENTS
            unless defining defaults
div{...}
  X
 ul{...}
 p{..}




AVOID STYLING ELEMENTS
            unless defining defaults
               .error{...}
              .section{...}
             .products{...}
.myModule .inner b{...}
.myModule2 b {...}


          GIVE RULES THE
         SAME STRENGTH
      Use cascade order to overwrite previous rules
X
.myModule .inner b{...}
.myModule2 b {...}


          GIVE RULES THE
         SAME STRENGTH
      Use cascade order to overwrite previous rules



     .myModule b{...}
     .myModule2 b {...}
.sidebar ul{...}
.header ul {...}


      AVOID SPECIFYING
         LOCATION
      Apply classes to the object you wish to change
X
.sidebar ul{...}
.header ul {...}


      AVOID SPECIFYING
         LOCATION
      Apply classes to the object you wish to change



     .mainNav{...}
     .subNav {...}
AVOID OVERLY SPECIFIC
      CLASSES
    they’re all semantic, but limiting
AVOID OVERLY SPECIFIC
      CLASSES
     they’re all semantic, but limiting

 .vehicle{...}
 .motorcycle{...}
 .ducati{...}
 .ducatiMonster620{...}
 .nicolesDucatiMonster620{...}
AVOID OVERLY SPECIFIC
      CLASSES
     they’re all semantic, but limiting

 .vehicle{...}
 .motorcycle{...}
 .ducati{...}

   X
 .ducatiMonster620{...}
 .nicolesDucatiMonster620{...}
#myUniqueIdentifier{...}
   #myUniqueIdentifier2{...}




                       AVOID SINGLETONS
                       ids can only be used once in any given page




Source: Chris Griego
X
   #myUniqueIdentifier{...}
   #myUniqueIdentifier2{...}




                       AVOID SINGLETONS
                       ids can only be used once in any given page




Source: Chris Griego
Media
                 Subheading
                 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
                 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
                 aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
                 cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.




                          USE MIXINS
                                 to avoid repeating code


Media Extended
Subheading
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
.inner{...}        .weatherMod .inner{...}
.tr{...}           .weatherMod .tr{...}
.bl{...}           .weatherMod .bl{...}



      ENCAPSULATION
     don’t access sub-nodes of an object directly



                          inner
.inner{...}
  X
                   .weatherMod .inner{...}
.tr{...}           .weatherMod .tr{...}
.bl{...}           .weatherMod .bl{...}



      ENCAPSULATION
     don’t access sub-nodes of an object directly



                          inner

More Related Content

What's hot (20)

PDF
What's Object-Oriented CSS (japanese)
shinobu tsutsui
 
PDF
SMACSS Workshop
Tim Hettler
 
PDF
Introduction to CSS3
RAHUL SHARMA
 
PDF
Css3 and gwt in perfect harmony
Arcbees
 
PDF
OOCSS, SMACSS or BEM?
Michael Posso
 
PDF
CSS 開發加速指南-Sass & Compass
Lucien Lee
 
PDF
CSS3 meets GWT with GSS
jdramaix
 
PPTX
Css3
Vladimir Varun
 
PDF
Efficient, maintainable CSS
Russ Weakley
 
PDF
Introduction to CSS3
Doris Chen
 
PDF
CSS: a rapidly changing world
Russ Weakley
 
PDF
The Near Future of CSS
Rachel Andrew
 
ODP
Introduction To Less
Knoldus Inc.
 
PDF
BEM it!
Max Shirshin
 
PPTX
New Elements & Features in CSS3
Jamshid Hashimi
 
PPTX
SASS is more than LESS
Itai Koren
 
PPTX
Css3
Deepak Mangal
 
PDF
CSS Reset
Russ Weakley
 
PPTX
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
Estelle Weyl
 
What's Object-Oriented CSS (japanese)
shinobu tsutsui
 
SMACSS Workshop
Tim Hettler
 
Introduction to CSS3
RAHUL SHARMA
 
Css3 and gwt in perfect harmony
Arcbees
 
OOCSS, SMACSS or BEM?
Michael Posso
 
CSS 開發加速指南-Sass & Compass
Lucien Lee
 
CSS3 meets GWT with GSS
jdramaix
 
Efficient, maintainable CSS
Russ Weakley
 
Introduction to CSS3
Doris Chen
 
CSS: a rapidly changing world
Russ Weakley
 
The Near Future of CSS
Rachel Andrew
 
Introduction To Less
Knoldus Inc.
 
BEM it!
Max Shirshin
 
New Elements & Features in CSS3
Jamshid Hashimi
 
SASS is more than LESS
Itai Koren
 
CSS Reset
Russ Weakley
 
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
Estelle Weyl
 

Similar to Taming CSS Selectors (20)

KEY
What is Object Oriented CSS?
Nicole Sullivan
 
PDF
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Christian Lilley
 
ODP
HTML5, CSS, JavaScript Style guide and coding conventions
Knoldus Inc.
 
PDF
Accelerated Stylesheets
Wynn Netherland
 
KEY
CSS Wish List @JSConf
Nicole Sullivan
 
PPT
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Deepak Sharma
 
PPT
Css best practices style guide and tips
Chris Love
 
PPTX
Css methods architecture
Lasha Sumbadze
 
PDF
A complete html and css guidelines for beginners
Surendra kumar
 
PDF
Front-End Methodologies
Arash Manteghi
 
PDF
Part 2 in depth guide on word-press coding standards for css & js big
eSparkBiz
 
PDF
Big Design Conference: CSS3
Wynn Netherland
 
PDF
Structuring your CSS for maintainability: rules and guile lines to write CSS
Sanjoy Kr. Paul
 
PDF
6 Steps to Make Your CSS Code More Maintainable
10Clouds
 
PPTX
CSS Architecture: Writing Maintainable CSS
Alexei Skachykhin
 
PDF
CSS: The Boring Bits
Peter Gasston
 
PPTX
CSS Walktrough Internship Course
Zoltan Iszlai
 
KEY
Sass Essentials at Mobile Camp LA
Jake Johnson
 
PDF
What is Modular CSS?
Scott Vandehey
 
PDF
Creative Web 02 - HTML & CSS Basics
Lukas Oppermann
 
What is Object Oriented CSS?
Nicole Sullivan
 
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Christian Lilley
 
HTML5, CSS, JavaScript Style guide and coding conventions
Knoldus Inc.
 
Accelerated Stylesheets
Wynn Netherland
 
CSS Wish List @JSConf
Nicole Sullivan
 
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Deepak Sharma
 
Css best practices style guide and tips
Chris Love
 
Css methods architecture
Lasha Sumbadze
 
A complete html and css guidelines for beginners
Surendra kumar
 
Front-End Methodologies
Arash Manteghi
 
Part 2 in depth guide on word-press coding standards for css & js big
eSparkBiz
 
Big Design Conference: CSS3
Wynn Netherland
 
Structuring your CSS for maintainability: rules and guile lines to write CSS
Sanjoy Kr. Paul
 
6 Steps to Make Your CSS Code More Maintainable
10Clouds
 
CSS Architecture: Writing Maintainable CSS
Alexei Skachykhin
 
CSS: The Boring Bits
Peter Gasston
 
CSS Walktrough Internship Course
Zoltan Iszlai
 
Sass Essentials at Mobile Camp LA
Jake Johnson
 
What is Modular CSS?
Scott Vandehey
 
Creative Web 02 - HTML & CSS Basics
Lukas Oppermann
 
Ad

More from Nicole Sullivan (13)

PDF
Building the Media Block in ReactJS
Nicole Sullivan
 
PDF
Why are you here?
Nicole Sullivan
 
PDF
Creating Living Style Guides to Improve Performance
Nicole Sullivan
 
PDF
Don't feed the trolls
Nicole Sullivan
 
PDF
CSS Power Tools
Nicole Sullivan
 
PDF
Our Best Practices Are Killing Us
Nicole Sullivan
 
PDF
CSS Bloat!
Nicole Sullivan
 
PDF
5 Mistakes of Massive CSS
Nicole Sullivan
 
KEY
Object Oriented CSS
Nicole Sullivan
 
PDF
Pourquoi la performance?
Nicole Sullivan
 
PDF
Design Fast Websites
Nicole Sullivan
 
PDF
7 Habits of Exceptional Performance
Nicole Sullivan
 
PPT
After YSlow "A"
Nicole Sullivan
 
Building the Media Block in ReactJS
Nicole Sullivan
 
Why are you here?
Nicole Sullivan
 
Creating Living Style Guides to Improve Performance
Nicole Sullivan
 
Don't feed the trolls
Nicole Sullivan
 
CSS Power Tools
Nicole Sullivan
 
Our Best Practices Are Killing Us
Nicole Sullivan
 
CSS Bloat!
Nicole Sullivan
 
5 Mistakes of Massive CSS
Nicole Sullivan
 
Object Oriented CSS
Nicole Sullivan
 
Pourquoi la performance?
Nicole Sullivan
 
Design Fast Websites
Nicole Sullivan
 
7 Habits of Exceptional Performance
Nicole Sullivan
 
After YSlow "A"
Nicole Sullivan
 
Ad

Recently uploaded (20)

PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
July Patch Tuesday
Ivanti
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Python basic programing language for automation
DanialHabibi2
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 

Taming CSS Selectors

  • 1. TAMING SELECTORS sanity for our stylesheets
  • 2. SIZE OF THE CSS FILE AND IMPLIED HTTP REQUESTS are the biggest factor for CSS performance
  • 3. REFLOWS AND RENDERING TIME are (much!) less important
  • 4. DUPLICATION IS WORSE THAN STALE RULES because we have tools to deal with the later
  • 5. DEFINE DEFAULT VALUES Don’t repeat this code in every object
  • 6. #weatherModule h3{color:red;} #tabs h3{color:blue} DEFINE DEFAULT VALUES Don’t repeat this code in every object
  • 7. X #weatherModule h3{color:red;} #tabs h3{color:blue} DEFINE DEFAULT VALUES Don’t repeat this code in every object
  • 8. X #weatherModule h3{color:red;} #tabs h3{color:blue} DEFINE DEFAULT VALUES Don’t repeat this code in every object h1, .h1{...} h2, .h2{...} h3, .h3{...} h4, .h4{...} h5, .h5{...} h6, .h6{...}
  • 9. DEFINE STRUCTURE IN A SEPARATE CLASS Don’t repeat this code in every object block inner hd bd ft
  • 10. div.error{...} STYLE CLASSES rather than elements
  • 11. X div.error{...} STYLE CLASSES rather than elements .error{ most of the code goes here }
  • 12. X div.error{...} STYLE CLASSES rather than elements .error{ most of the code goes here } div.error{ } p.error{ exceptions only } em.error{ }
  • 13. div{...} ul{...} p{..} AVOID STYLING ELEMENTS unless defining defaults
  • 14. div{...} X ul{...} p{..} AVOID STYLING ELEMENTS unless defining defaults .error{...} .section{...} .products{...}
  • 15. .myModule .inner b{...} .myModule2 b {...} GIVE RULES THE SAME STRENGTH Use cascade order to overwrite previous rules
  • 16. X .myModule .inner b{...} .myModule2 b {...} GIVE RULES THE SAME STRENGTH Use cascade order to overwrite previous rules .myModule b{...} .myModule2 b {...}
  • 17. .sidebar ul{...} .header ul {...} AVOID SPECIFYING LOCATION Apply classes to the object you wish to change
  • 18. X .sidebar ul{...} .header ul {...} AVOID SPECIFYING LOCATION Apply classes to the object you wish to change .mainNav{...} .subNav {...}
  • 19. AVOID OVERLY SPECIFIC CLASSES they’re all semantic, but limiting
  • 20. AVOID OVERLY SPECIFIC CLASSES they’re all semantic, but limiting .vehicle{...} .motorcycle{...} .ducati{...} .ducatiMonster620{...} .nicolesDucatiMonster620{...}
  • 21. AVOID OVERLY SPECIFIC CLASSES they’re all semantic, but limiting .vehicle{...} .motorcycle{...} .ducati{...} X .ducatiMonster620{...} .nicolesDucatiMonster620{...}
  • 22. #myUniqueIdentifier{...} #myUniqueIdentifier2{...} AVOID SINGLETONS ids can only be used once in any given page Source: Chris Griego
  • 23. X #myUniqueIdentifier{...} #myUniqueIdentifier2{...} AVOID SINGLETONS ids can only be used once in any given page Source: Chris Griego
  • 24. Media Subheading Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. USE MIXINS to avoid repeating code Media Extended Subheading Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  • 25. .inner{...} .weatherMod .inner{...} .tr{...} .weatherMod .tr{...} .bl{...} .weatherMod .bl{...} ENCAPSULATION don’t access sub-nodes of an object directly inner
  • 26. .inner{...} X .weatherMod .inner{...} .tr{...} .weatherMod .tr{...} .bl{...} .weatherMod .bl{...} ENCAPSULATION don’t access sub-nodes of an object directly inner