SlideShare a Scribd company logo
1 of 40
OOCSS &
       Progressive CSS3
       Selectors




By: Daniel Sternlicht     http://www.danielsternlicht.com
CSS Selectors
  All over again…
Element

   p{
        text-align: center;
   }

   a{
        text-decoration: underline;
        color: blue;
   }
#ID

      #wrapper {
          text-decoration: underline;
          color: #fff;
      }
.Class

   .box {
         text-decoration: underline;
         color: #fff;
   }
* All
    *{
         text-decoration: underline;
         color: #fff;
    }

    div * {
          text-decoration: underline;
          color: #fff;
    }
Child Selector

   .box p {
        text-decoration: underline;
        color: #fff;
   }
   .box div ul li p span.error {
        background: red;
        padding: 5px;
   }
Direct > Children

   ul li {
             text-decoration: underline;
             color: #fff;
   }
   ul > li {
          text-decoration: underline;
          color: #fff;
   }
Adjacent + Selector

   ul + p {
         text-decoration: underline;
         color: #fff;
   }

   Select the first “p” after each “ul”
Sibling ~ Selector

   ul ~ p {
         text-decoration: underline;
         color: #fff;
   }
   ul + p {
         text-decoration: underline;
         color: #fff;
   }
:hover

   a:hover {
        text-decoration: undeline;
        color: blue;
   }
::first-letter

    p::first-letter {
           font-size: 56px;
           color: blue;
    }
    p::first-line {
           font-weight: bold;
           color: yellow;
    }
CSS3
Selectors
:checked

           input[type=radio]:checked {
                border: 1px solid red;
                padding: 10px;
           }




http://tympanus.net/Tutorials/CSS3Accordion/index.html
:not(selector)

   *:not(p) {
        background: #000;
        margin: 0 auto;
   }
   div:not(#container) {
        background: #000;
        margin: 0 auto;
   }
:nth-child(n)
   ul > li:nth-child(2) {
          text-decoration: underline;
          color: #fff;
   }
   ul > li:nth-child(6n) {
          text-decoration: underline;
          color: #fff;
   }
:nth-last-child(n)

   ul > li:nth-last-child(3) {
          text-decoration: underline;
          color: #fff;
   }

   Start counting from the end
:nth-of-type(n)

   div ul:nth-of-type(2) {
         text-shadow: 1px 1px 0 #000;
         padding: 5px;
   }

   Select the second element from a specific type
:nth-last-of-type(n)

   ul:nth-last-of-type(2) {
         text-shadow: 1px 1px 0 #000;
         padding: 5px;
   }
:first-child

    ul li:first-child {
            text-shadow: 1px 1px 0 #000;
            padding: 5px;
    }
    ul li:nth-child(1) {
           text-shadow: 1px 1px 0 #000;
           padding: 5px;
    }
:last-child

    ul li:last-child {
           text-shadow: 1px 1px 0 #000;
           padding: 5px;
    }
    ul li:nth-last-child(1) {
           text-shadow: 1px 1px 0 #000;
           padding: 5px;
    }
:only-child

   div p:only-child {
         display: none;
   }

   Select only if the element is the only child
:only-of-type

   div p:only-of-type {
         display: none;
   }
OOCSS
Object Oriented CSS
Say What?!
Purpose

Code Reuse    Shrinks CSS Files   Faster Webapps
Principles
Structure

            Skin
#button {                       .button {
width: 200px;                   width: 200px;
height: 50px;                   height: 50px;
padding: 10px;                  }
border: solid 1px #ccc;
background: red;                .box {
box-shadow: 2px 2px 5px #000;   width: 400px;
}                               overflow: hidden;
                                }
#box {
width: 400px;                   .widget {
overflow: hidden;               width: 500px;
border: solid 1px #ccc;         min-height: 200px;
Background: red;                overflow: auto;
box-shadow: 2px 2px 5px #000;   }
}
                                .skin {
#widget {                       border: solid 1px #ccc;
width: 500px;                   background: red;
min-height: 200px;              box-shadow: 2px 2px 5px #000;
overflow: auto;                 }
border: solid 1px #ccc;
background: red;
box-shadow: 2px 2px 5px #000;
}



                                                     ID 2 Class
Content

          Containers
<header>                  Header

         Header content

</header>

<div id="wrapper">

         Main content
                          Content
</div>

<footer>

         Footer content

</footer>
                          Footer
header {
width: 960px;
margin: 0px auto;
padding: 10px;
border-bottom: 1px solid #c7c7c7;
box-shadow: 2px 2px 5px #000;
}
                                    .globalWidth {
#wrapper {                          width: 960px;
width: 960px;                       margin: 0px auto;
margin: 0px auto;                   padding: 10px;
padding: 10px;                      }
Background: red;
box-shadow: 2px 2px 5px #000;
}

footer {
width: 960px;
margin: 0px auto;
padding: 10px;
min-height: 10px;
box-shadow: 2px 2px 5px #000;
}




                                                        ID 2 Class
Guidelines
• Avoid IDs as styling hooks

• Avoid attaching classes to element in your
stylesheet (p.error)

• Don’t ever use !important

• Use / Write your own CSS Grids

• Test your CSS code with CSS Lint
Why?
Faster
Websites
Speed
Maintainable
Stylesheets
OOCSS.com
Questions?

More Related Content

Viewers also liked (7)

Html basics
Html basicsHtml basics
Html basics
 
JS App Architecture
JS App ArchitectureJS App Architecture
JS App Architecture
 
Basics of html for web development by software outsourcing company india
Basics of html for web development   by software outsourcing company indiaBasics of html for web development   by software outsourcing company india
Basics of html for web development by software outsourcing company india
 
Css3
Css3Css3
Css3
 
HTML and CSS Basics
HTML and CSS BasicsHTML and CSS Basics
HTML and CSS Basics
 
CSS3: Ripe and Ready to Respond
CSS3: Ripe and Ready to RespondCSS3: Ripe and Ready to Respond
CSS3: Ripe and Ready to Respond
 
CSS3
CSS3CSS3
CSS3
 

Similar to Oocss & progressive css3 selectors

Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Kaelig Deloumeau-Prigent
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
Week ThreeExpress Holidayscssstyle.csshtml{ height 100.docx
Week ThreeExpress Holidayscssstyle.csshtml{ height 100.docxWeek ThreeExpress Holidayscssstyle.csshtml{ height 100.docx
Week ThreeExpress Holidayscssstyle.csshtml{ height 100.docx
philipnelson29183
 
Software programming tools for creating/managing CSS files
Software programming tools for creating/managing CSS filesSoftware programming tools for creating/managing CSS files
Software programming tools for creating/managing CSS files
Dinu Suman
 
My discussion Student A A8 - Cross-Site Request Forgery (CSR.docx
My discussion Student A A8 - Cross-Site Request Forgery (CSR.docxMy discussion Student A A8 - Cross-Site Request Forgery (CSR.docx
My discussion Student A A8 - Cross-Site Request Forgery (CSR.docx
gilpinleeanna
 
Doctype html publi
Doctype html publiDoctype html publi
Doctype html publi
Eddy_TKJ
 

Similar to Oocss & progressive css3 selectors (20)

CSS for Developers
CSS for DevelopersCSS for Developers
CSS for Developers
 
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
 
Learn to Love CSS3 [English]
Learn to Love CSS3 [English]Learn to Love CSS3 [English]
Learn to Love CSS3 [English]
 
Accelerated Stylesheets
Accelerated StylesheetsAccelerated Stylesheets
Accelerated Stylesheets
 
HTML&CSS 5 - Intermediate CSS (2/2)
HTML&CSS 5 - Intermediate CSS (2/2)HTML&CSS 5 - Intermediate CSS (2/2)
HTML&CSS 5 - Intermediate CSS (2/2)
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
Prototyping w/HTML5 and CSS3
Prototyping w/HTML5 and CSS3Prototyping w/HTML5 and CSS3
Prototyping w/HTML5 and CSS3
 
Exam 70 480 CSS3 at Jinal Desai .NET
Exam 70 480 CSS3 at Jinal Desai .NETExam 70 480 CSS3 at Jinal Desai .NET
Exam 70 480 CSS3 at Jinal Desai .NET
 
Week ThreeExpress Holidayscssstyle.csshtml{ height 100.docx
Week ThreeExpress Holidayscssstyle.csshtml{ height 100.docxWeek ThreeExpress Holidayscssstyle.csshtml{ height 100.docx
Week ThreeExpress Holidayscssstyle.csshtml{ height 100.docx
 
Worth the hype - styled components
Worth the hype - styled componentsWorth the hype - styled components
Worth the hype - styled components
 
Software programming tools for creating/managing CSS files
Software programming tools for creating/managing CSS filesSoftware programming tools for creating/managing CSS files
Software programming tools for creating/managing CSS files
 
Xlrays online web tutorials
Xlrays online web tutorialsXlrays online web tutorials
Xlrays online web tutorials
 
Getting Started with Sass & Compass
Getting Started with Sass & CompassGetting Started with Sass & Compass
Getting Started with Sass & Compass
 
Tmx9
Tmx9Tmx9
Tmx9
 
Wrangling the CSS Beast with Sass
Wrangling the CSS Beast  with SassWrangling the CSS Beast  with Sass
Wrangling the CSS Beast with Sass
 
Simplify your CSS with Stylus and Nib
Simplify your CSS with Stylus and NibSimplify your CSS with Stylus and Nib
Simplify your CSS with Stylus and Nib
 
My discussion Student A A8 - Cross-Site Request Forgery (CSR.docx
My discussion Student A A8 - Cross-Site Request Forgery (CSR.docxMy discussion Student A A8 - Cross-Site Request Forgery (CSR.docx
My discussion Student A A8 - Cross-Site Request Forgery (CSR.docx
 
CSS3 and Selectors
CSS3 and SelectorsCSS3 and Selectors
CSS3 and Selectors
 
Doctype html publi
Doctype html publiDoctype html publi
Doctype html publi
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 

Oocss & progressive css3 selectors

  • 1. OOCSS & Progressive CSS3 Selectors By: Daniel Sternlicht http://www.danielsternlicht.com
  • 2. CSS Selectors All over again…
  • 3. Element p{ text-align: center; } a{ text-decoration: underline; color: blue; }
  • 4. #ID #wrapper { text-decoration: underline; color: #fff; }
  • 5. .Class .box { text-decoration: underline; color: #fff; }
  • 6. * All *{ text-decoration: underline; color: #fff; } div * { text-decoration: underline; color: #fff; }
  • 7. Child Selector .box p { text-decoration: underline; color: #fff; } .box div ul li p span.error { background: red; padding: 5px; }
  • 8. Direct > Children ul li { text-decoration: underline; color: #fff; } ul > li { text-decoration: underline; color: #fff; }
  • 9. Adjacent + Selector ul + p { text-decoration: underline; color: #fff; } Select the first “p” after each “ul”
  • 10. Sibling ~ Selector ul ~ p { text-decoration: underline; color: #fff; } ul + p { text-decoration: underline; color: #fff; }
  • 11. :hover a:hover { text-decoration: undeline; color: blue; }
  • 12. ::first-letter p::first-letter { font-size: 56px; color: blue; } p::first-line { font-weight: bold; color: yellow; }
  • 14. :checked input[type=radio]:checked { border: 1px solid red; padding: 10px; } http://tympanus.net/Tutorials/CSS3Accordion/index.html
  • 15. :not(selector) *:not(p) { background: #000; margin: 0 auto; } div:not(#container) { background: #000; margin: 0 auto; }
  • 16. :nth-child(n) ul > li:nth-child(2) { text-decoration: underline; color: #fff; } ul > li:nth-child(6n) { text-decoration: underline; color: #fff; }
  • 17. :nth-last-child(n) ul > li:nth-last-child(3) { text-decoration: underline; color: #fff; } Start counting from the end
  • 18. :nth-of-type(n) div ul:nth-of-type(2) { text-shadow: 1px 1px 0 #000; padding: 5px; } Select the second element from a specific type
  • 19. :nth-last-of-type(n) ul:nth-last-of-type(2) { text-shadow: 1px 1px 0 #000; padding: 5px; }
  • 20. :first-child ul li:first-child { text-shadow: 1px 1px 0 #000; padding: 5px; } ul li:nth-child(1) { text-shadow: 1px 1px 0 #000; padding: 5px; }
  • 21. :last-child ul li:last-child { text-shadow: 1px 1px 0 #000; padding: 5px; } ul li:nth-last-child(1) { text-shadow: 1px 1px 0 #000; padding: 5px; }
  • 22. :only-child div p:only-child { display: none; } Select only if the element is the only child
  • 23. :only-of-type div p:only-of-type { display: none; }
  • 26. Purpose Code Reuse Shrinks CSS Files Faster Webapps
  • 28. Structure Skin
  • 29. #button { .button { width: 200px; width: 200px; height: 50px; height: 50px; padding: 10px; } border: solid 1px #ccc; background: red; .box { box-shadow: 2px 2px 5px #000; width: 400px; } overflow: hidden; } #box { width: 400px; .widget { overflow: hidden; width: 500px; border: solid 1px #ccc; min-height: 200px; Background: red; overflow: auto; box-shadow: 2px 2px 5px #000; } } .skin { #widget { border: solid 1px #ccc; width: 500px; background: red; min-height: 200px; box-shadow: 2px 2px 5px #000; overflow: auto; } border: solid 1px #ccc; background: red; box-shadow: 2px 2px 5px #000; } ID 2 Class
  • 30. Content Containers
  • 31. <header> Header Header content </header> <div id="wrapper"> Main content Content </div> <footer> Footer content </footer> Footer
  • 32. header { width: 960px; margin: 0px auto; padding: 10px; border-bottom: 1px solid #c7c7c7; box-shadow: 2px 2px 5px #000; } .globalWidth { #wrapper { width: 960px; width: 960px; margin: 0px auto; margin: 0px auto; padding: 10px; padding: 10px; } Background: red; box-shadow: 2px 2px 5px #000; } footer { width: 960px; margin: 0px auto; padding: 10px; min-height: 10px; box-shadow: 2px 2px 5px #000; } ID 2 Class
  • 34. • Avoid IDs as styling hooks • Avoid attaching classes to element in your stylesheet (p.error) • Don’t ever use !important • Use / Write your own CSS Grids • Test your CSS code with CSS Lint
  • 35. Why?
  • 37. Speed