SlideShare uma empresa Scribd logo
1 de 18
CSS
  Chained classes




Julien BRAURE – julien@jazar.co.uk
CSS – Chained classes




     •What is CSS ?

     •Quick overview

     •Chained classes

     •Examples

     •Conclusion

     •Questions and maybe answers




CSS – Chained classes
What is CSS ?


   •CSS : Cascading Style Sheet

   •Separate Content         and     Presentation

                  HTML                      CSS
                 <html>        +      body {            =
                  <body>                color: #fff;
                                      }




   •Save server load
             Page1 ?
                                     HTML
                                     Page              CSS
                                       1



              Page 2 ?
                                     HTML
                                     Page
                                       2


   •Reduce maintenance time

   Change in the design ? only update the CSS file



CSS – Chained classes
Quick overview




  HTML                                           CSS

  <markup class=“class1” id=“this-one” />        markup.class1#this-one {
                                                           /* here goes the declarations */
                                                           color: #f00;
                                                           border: 1px solid #000;
                                                 }


                            classes are prefix with a dot (.)
                            id is prefix with a sharp (#)




CSS – Chained classes
Chained classes (HTML side)


    •In HTML the class attribute, may have multiple classes, space separated
    <p class=“class1 class2 ... classN”>


  HTML                                          CSS

  <p class=“class1”>                            p.class1 {
      Lorem ipsum dolor sit amet.                            color: red;
  </p>                                          }

  <p class=“class2”>                            p.class2 {
      Lorem ipsum dolor sit amet.                            font-weight: bold;
  </p>                                          }

  <p class=“class1 class2”>
      Lorem ipsum dolor sit amet.
  </p>


                        CSS declarations are merging ...
                        This paragraph is red AND bold




CSS – Chained classes
Chained classes (CSS side)


    •In HTML the class attribute, may have multiple classes, space separated
    <p class=“class1 class2 ... classN”>


  HTML                                              CSS

  <p class=“class1”>                                p.class1 {
      Lorem ipsum dolor sit amet.                                 color: red;
  </p>                                              }

  <p class=“class2”>                                p.class2 {
      Lorem ipsum dolor sit amet.                                 font-weight: bold;
  </p>                                              }

  <p class=“class1 class2”>                         p.class1.class2 {
      Lorem ipsum dolor sit amet.                                 text-decoration: underline;
  </p>                                              }


  CSS declarations are merging ...                  This declarations only applies to markup
  This paragraph is red, bold AND underlined        with class1 AND class2



                                    Chained classes :
                                    •HTML : space separated
                                    •CSS : concatenated
CSS – Chained classes
Chained classes (CSS side)


    •In HTML the class attribute, may have multiple classes, space separated
    <p class=“class1 class2 ... classN”>


  HTML                                     CSS

  <p class=“class1”>                       p.class1 {                         overwrites
      Lorem ipsum dolor sit amet.                        color: red;
  </p>                                     }

  <p class=“class2”>                       p.class2 {
      Lorem ipsum dolor sit amet.                        font-weight: bold;
  </p>                                     }

  <p class=“class1 class2”>                p.class1.class2 {
      Lorem ipsum dolor sit amet.                        text-decoration: underline;
  </p>                                                   color: green;
                                           }




CSS – Chained classes
Chained classes – Example 1


    Messages: success, error, info




CSS – Chained classes
Chained classes - Example

    HTML                                               CSS


                                                     p.message {
                                                       border: 2px solid;
                                      Common           padding: 16px 8px 16px 48px;
                                      declarations     background-repeat: no-repeat;
                                                       background-position: 8px center;
                                                     }




                                                     p.message.success {
    <p class=“message success”>                        border-color: green;
        Great !                                        color: green;
        It has been done.                              background-image: url(img/message.success.gif);
    </p>                                             }

                                                     p.message.error {
    <p class=“message error”>                          border-color: red;
        Bad luck !                                     color: red;
        Some error happens.                            background-image: url(img/message.error.gif);
    </p>                                             }

                                                     p.message.info {
    <p class=“message info”>                           border-color: blue;
        Some important information.                    color: blue;
    </p>                                               background-image: url(img/message.info.gif);
                                                     }

CSS – Chained classes
Chained classes – Example 2 - Site wide organisation




     •Insurance website
          •Static contents
               •Faq’s
               •Legal informations
               •Some other contents
          •Dynamic sections
               •Cars insurance
               •Houses insurance



     •Design
         •Static:
              •Grey
         •Dynamic:
              •Car section: red
              •House section: blue


CSS – Chained classes
Chained classes – Example 2 - Site wide organisation


     •Basic layout:




                        <div id=“header”>
                        </div>

                        <div class=“page”>
                            <h1>title of the page</h1>

                            <p>some content</p>
                            <p>some content</p>
                            <p>some content</p>
                        </div>

                        <div id=“footer”>
                        </div>



CSS – Chained classes
Chained classes – Example 2 - Site wide organisation

     •Sample sitemap
                                                                .page

      .dynamic                    .static
                                     .faq
        .car
                                            #q1    #q2
          #step1        #step2
                                                          ...

                                     .legal

        .house                              #tos

          #step1        #step2


                                       #contact




CSS – Chained classes
Chained classes – Example 2 - Site wide organisation

     •Sample sitemap
                                                                   .page

      .dynamic                    .static

                                     .faq
        .car
               <div class=“page dynamic house” id=“step2”>
                                         #q1       #q2
          #step1
               </div>#step2
                                                             ...

                                     .legal

        .house                              #tos

          #step1        #step2


                                       #contact




CSS – Chained classes
Chained classes – Example 2 - Site wide organisation

     •Sample sitemap
                                                                     .page

      .dynamic                       .static

                                        .faq
        .car
                                               #q1    #q2
          #step1        #step2
                                                               ...

                                        .legal

        .house                                 #tos

          #step1        #step2


                                          #contact
                                 <div class=“page static legal” id=“tos”>
                                 </div>


CSS – Chained classes
Chained classes – Example 2 - Site wide organisation

                                           CSS

                                         .page h1 {
                          Common            font-size: 16px;
                          declarations   }


                                         .page.static h1 {
                                            background-color: grey;
                                         }


                                         .page.dynamic.car h1 {
                                            background-color: red;
                                         }


                                         .page.dynamic.house h1 {
                                            background-color: blue;
                                         }




CSS – Chained classes
Chained classes – Example 2 - Site wide organisation


    Customized messages on car pages ?




    .page.dynamic.car .message.success {
          background-image: url(img/dynamic/car/message.success.gif);
    }




CSS – Chained classes
Conclusion


     •Real separation between content and presentation


     •Ability to deploy rapidly alternative design, for Christmas for example



    To keep in mind

     •In my HTML:       what I want to say
     •In my CSS:        how I want to render it

     •Avoid presentation related classes in HTML
         Eg: bold, small, rounded, ...




CSS – Chained classes
Questions ?




                        Any questions ?




CSS – Chained classes

Mais conteúdo relacionado

Semelhante a CSS - chained classes

Html Css
Html CssHtml Css
Html Csspumas26
 
jQuery and Ruby Web Frameworks
jQuery and Ruby Web FrameworksjQuery and Ruby Web Frameworks
jQuery and Ruby Web FrameworksYehuda Katz
 
Haml And Sass: Put your markup on a diet
Haml And Sass: Put your markup on a dietHaml And Sass: Put your markup on a diet
Haml And Sass: Put your markup on a dietdavidsidlinger
 
this is ruby test
this is ruby testthis is ruby test
this is ruby test51 lecture
 
Standardizing the Web: A Look into the Why of Web Standards
Standardizing the Web: A Look into the Why of Web StandardsStandardizing the Web: A Look into the Why of Web Standards
Standardizing the Web: A Look into the Why of Web StandardsTim Wright
 
What I discovered about layout vis CSS Grid
What I discovered about layout vis CSS GridWhat I discovered about layout vis CSS Grid
What I discovered about layout vis CSS GridRachel Andrew
 
Webcast 09/2008 - Silverlight 2 Beta 2
Webcast 09/2008 - Silverlight 2 Beta 2Webcast 09/2008 - Silverlight 2 Beta 2
Webcast 09/2008 - Silverlight 2 Beta 2sleguiza
 
Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Bastian Feder
 
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 NewsKaelig Deloumeau-Prigent
 
Google Developers Experts Summit 2017 - CSS Layout
Google Developers Experts Summit 2017 - CSS Layout Google Developers Experts Summit 2017 - CSS Layout
Google Developers Experts Summit 2017 - CSS Layout Rachel Andrew
 
When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Railsdosire
 
An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)Ardee Aram
 
W2Tags Is Haml In Erb
W2Tags Is Haml In ErbW2Tags Is Haml In Erb
W2Tags Is Haml In Erbwidi harsojo
 
Compass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperCompass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperWynn Netherland
 
Doing more with LESS
Doing more with LESSDoing more with LESS
Doing more with LESSjsmith92
 
3 coding101 fewd_lesson3_your_first_website 20210105
3 coding101 fewd_lesson3_your_first_website 202101053 coding101 fewd_lesson3_your_first_website 20210105
3 coding101 fewd_lesson3_your_first_website 20210105John Picasso
 

Semelhante a CSS - chained classes (20)

Html Css
Html CssHtml Css
Html Css
 
jQuery and Ruby Web Frameworks
jQuery and Ruby Web FrameworksjQuery and Ruby Web Frameworks
jQuery and Ruby Web Frameworks
 
Haml And Sass: Put your markup on a diet
Haml And Sass: Put your markup on a dietHaml And Sass: Put your markup on a diet
Haml And Sass: Put your markup on a diet
 
this is ruby test
this is ruby testthis is ruby test
this is ruby test
 
Standardizing the Web: A Look into the Why of Web Standards
Standardizing the Web: A Look into the Why of Web StandardsStandardizing the Web: A Look into the Why of Web Standards
Standardizing the Web: A Look into the Why of Web Standards
 
What I discovered about layout vis CSS Grid
What I discovered about layout vis CSS GridWhat I discovered about layout vis CSS Grid
What I discovered about layout vis CSS Grid
 
Practical Groovy DSL
Practical Groovy DSLPractical Groovy DSL
Practical Groovy DSL
 
Accelerated Stylesheets
Accelerated StylesheetsAccelerated Stylesheets
Accelerated Stylesheets
 
Webcast 09/2008 - Silverlight 2 Beta 2
Webcast 09/2008 - Silverlight 2 Beta 2Webcast 09/2008 - Silverlight 2 Beta 2
Webcast 09/2008 - Silverlight 2 Beta 2
 
Haml, Sass & Compass
Haml, Sass & CompassHaml, Sass & Compass
Haml, Sass & Compass
 
Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009
 
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
 
Google Developers Experts Summit 2017 - CSS Layout
Google Developers Experts Summit 2017 - CSS Layout Google Developers Experts Summit 2017 - CSS Layout
Google Developers Experts Summit 2017 - CSS Layout
 
The Future of CSS
The Future of CSSThe Future of CSS
The Future of CSS
 
When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Rails
 
An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)
 
W2Tags Is Haml In Erb
W2Tags Is Haml In ErbW2Tags Is Haml In Erb
W2Tags Is Haml In Erb
 
Compass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperCompass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS Developer
 
Doing more with LESS
Doing more with LESSDoing more with LESS
Doing more with LESS
 
3 coding101 fewd_lesson3_your_first_website 20210105
3 coding101 fewd_lesson3_your_first_website 202101053 coding101 fewd_lesson3_your_first_website 20210105
3 coding101 fewd_lesson3_your_first_website 20210105
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
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 challengesrafiqahmad00786416
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
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 ...apidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
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 SavingEdi Saputra
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
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.pptxRemote DBA Services
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
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 ModelDeepika Singh
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
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...Orbitshub
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 

Último (20)

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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 ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

CSS - chained classes

  • 1. CSS Chained classes Julien BRAURE – julien@jazar.co.uk
  • 2. CSS – Chained classes •What is CSS ? •Quick overview •Chained classes •Examples •Conclusion •Questions and maybe answers CSS – Chained classes
  • 3. What is CSS ? •CSS : Cascading Style Sheet •Separate Content and Presentation HTML CSS <html> + body { = <body> color: #fff; } •Save server load Page1 ? HTML Page CSS 1 Page 2 ? HTML Page 2 •Reduce maintenance time Change in the design ? only update the CSS file CSS – Chained classes
  • 4. Quick overview HTML CSS <markup class=“class1” id=“this-one” /> markup.class1#this-one { /* here goes the declarations */ color: #f00; border: 1px solid #000; } classes are prefix with a dot (.) id is prefix with a sharp (#) CSS – Chained classes
  • 5. Chained classes (HTML side) •In HTML the class attribute, may have multiple classes, space separated <p class=“class1 class2 ... classN”> HTML CSS <p class=“class1”> p.class1 { Lorem ipsum dolor sit amet. color: red; </p> } <p class=“class2”> p.class2 { Lorem ipsum dolor sit amet. font-weight: bold; </p> } <p class=“class1 class2”> Lorem ipsum dolor sit amet. </p> CSS declarations are merging ... This paragraph is red AND bold CSS – Chained classes
  • 6. Chained classes (CSS side) •In HTML the class attribute, may have multiple classes, space separated <p class=“class1 class2 ... classN”> HTML CSS <p class=“class1”> p.class1 { Lorem ipsum dolor sit amet. color: red; </p> } <p class=“class2”> p.class2 { Lorem ipsum dolor sit amet. font-weight: bold; </p> } <p class=“class1 class2”> p.class1.class2 { Lorem ipsum dolor sit amet. text-decoration: underline; </p> } CSS declarations are merging ... This declarations only applies to markup This paragraph is red, bold AND underlined with class1 AND class2 Chained classes : •HTML : space separated •CSS : concatenated CSS – Chained classes
  • 7. Chained classes (CSS side) •In HTML the class attribute, may have multiple classes, space separated <p class=“class1 class2 ... classN”> HTML CSS <p class=“class1”> p.class1 { overwrites Lorem ipsum dolor sit amet. color: red; </p> } <p class=“class2”> p.class2 { Lorem ipsum dolor sit amet. font-weight: bold; </p> } <p class=“class1 class2”> p.class1.class2 { Lorem ipsum dolor sit amet. text-decoration: underline; </p> color: green; } CSS – Chained classes
  • 8. Chained classes – Example 1 Messages: success, error, info CSS – Chained classes
  • 9. Chained classes - Example HTML CSS p.message { border: 2px solid; Common padding: 16px 8px 16px 48px; declarations background-repeat: no-repeat; background-position: 8px center; } p.message.success { <p class=“message success”> border-color: green; Great ! color: green; It has been done. background-image: url(img/message.success.gif); </p> } p.message.error { <p class=“message error”> border-color: red; Bad luck ! color: red; Some error happens. background-image: url(img/message.error.gif); </p> } p.message.info { <p class=“message info”> border-color: blue; Some important information. color: blue; </p> background-image: url(img/message.info.gif); } CSS – Chained classes
  • 10. Chained classes – Example 2 - Site wide organisation •Insurance website •Static contents •Faq’s •Legal informations •Some other contents •Dynamic sections •Cars insurance •Houses insurance •Design •Static: •Grey •Dynamic: •Car section: red •House section: blue CSS – Chained classes
  • 11. Chained classes – Example 2 - Site wide organisation •Basic layout: <div id=“header”> </div> <div class=“page”> <h1>title of the page</h1> <p>some content</p> <p>some content</p> <p>some content</p> </div> <div id=“footer”> </div> CSS – Chained classes
  • 12. Chained classes – Example 2 - Site wide organisation •Sample sitemap .page .dynamic .static .faq .car #q1 #q2 #step1 #step2 ... .legal .house #tos #step1 #step2 #contact CSS – Chained classes
  • 13. Chained classes – Example 2 - Site wide organisation •Sample sitemap .page .dynamic .static .faq .car <div class=“page dynamic house” id=“step2”> #q1 #q2 #step1 </div>#step2 ... .legal .house #tos #step1 #step2 #contact CSS – Chained classes
  • 14. Chained classes – Example 2 - Site wide organisation •Sample sitemap .page .dynamic .static .faq .car #q1 #q2 #step1 #step2 ... .legal .house #tos #step1 #step2 #contact <div class=“page static legal” id=“tos”> </div> CSS – Chained classes
  • 15. Chained classes – Example 2 - Site wide organisation CSS .page h1 { Common font-size: 16px; declarations } .page.static h1 { background-color: grey; } .page.dynamic.car h1 { background-color: red; } .page.dynamic.house h1 { background-color: blue; } CSS – Chained classes
  • 16. Chained classes – Example 2 - Site wide organisation Customized messages on car pages ? .page.dynamic.car .message.success { background-image: url(img/dynamic/car/message.success.gif); } CSS – Chained classes
  • 17. Conclusion •Real separation between content and presentation •Ability to deploy rapidly alternative design, for Christmas for example To keep in mind •In my HTML: what I want to say •In my CSS: how I want to render it •Avoid presentation related classes in HTML Eg: bold, small, rounded, ... CSS – Chained classes
  • 18. Questions ? Any questions ? CSS – Chained classes