SlideShare une entreprise Scribd logo
1  sur  45
OOCSS
     &
  SMACSS
Stanislav Usoltsev
Overview
•   Encapsulation
•   Inheritance
•   Polymorphism
•   Mixins
•   Aggregation
•   Composition
•   Namespaces
•   States

                        2
Encapsulation
<div style=“width: 50%; color: red;”>
    Inline Styles
</div>




                                        3
Encapsulation
<div style=“width: 50%; color: red;”>
    Inline Styles
</div>
<div class=“cls1”>
    Use .class
</div>



                                        4
Inheritance
.cls1 {
     width: 50%; color: red;
}

.subcls1 {
    /* new properties */
}

                               5
Inheritance :: Type #1
.cls1 {
     width: 50%; color: red;
}

/* via classes */

.cls1.subcls1 {
     …
}

                               6
Inheritance :: Type #1
.btns {
    background: url(„sprite.png‟);
}

.btns.submit {
    background-position: -40px 0;
}

                                     7
Inheritance :: Type #1
class Button {
     protected $_background;
}

class ButtonSubmit extends Button {
     protected $_bg_position_x = 40,
               $_bg_position_y = 0;
}

                                       8
Inheritance :: Type #1




0     0   0   0   0   0   0   0




                                  9
Inheritance :: Type #1



         !important
inline   #ID   .class   tag   inline   #ID   .class   tag
  0       0      0      0       0       0      0      0




                                                            10
Inheritance :: Type #1



           !important
 inline   #ID    .class   tag   inline   #ID   .class   tag
   0       0       0      0       0       0      0      0


Bad Practice




                                                              11
Inheritance :: Type #1



           !important
 inline   #ID    .class   tag   inline   #ID   .class   tag
   0       0       0      0       0       0      0      0


Bad Practice




                                                              12
Inheritance :: Type #1



          !important
 inline   #ID   .class   tag   inline   #ID   .class   tag
   0       0      0      0       0       0      0      0


Don‟t use #ID in OOCSS and SMACSS
Use #ID for JavaScript




                                                             13
Inheritance :: Type #1



          !important
 inline   #ID   .class   tag   inline   #ID   .class   tag
   0       0      0      0       0       0      0      0


Don‟t use tags in OOCSS and SMACSS
Tags - unpredictable




                                                             14
Inheritance :: Type #1
.btns {                                .class
                                         1
    background: url(„sprite.png‟);
}

.btns.submit {                         .class
                                         2
    background-position: -40px 0;
}
                                     + cascade

                                             15
Inheritance :: Type #2
.cls1 {
     width: 50%; color: red;
}

/* via media queries */

@media … {
   …
}

                               16
Inheritance :: Type #2
Init: 960gs, 12units




                               17
Inheritance :: Type #2
Init: 960gs, 12units
.unit-1    { width: 60px; margin: 10px; }
.unit-2    { width: 140px; margin: 10px; }
.unit-3    { width: 220px; margin: 10px; }
.unit-4    { width: 300px; margin: 10px; }
.unit-5    { width: 380px; margin: 10px; }
.unit-6    { width: 460px; margin: 10px; }
.unit-7    { width: 540px; margin: 10px; }
.unit-8    { width: 620px; margin: 10px; }
.unit-9    { width: 700px; margin: 10px; }
.unit-10   { width: 780px; margin: 10px; }
.unit-11   { width: 860px; margin: 10px; }
.unit-12   { width: 940px; margin: 10px; }




                                             18
Inheritance :: Type #2
Init: 960gs, 12units                         Final: 1280gs, 16units
.unit-1    { width: 60px; margin: 10px; }
.unit-2    { width: 140px; margin: 10px; }
.unit-3    { width: 220px; margin: 10px; }
.unit-4    { width: 300px; margin: 10px; }
.unit-5    { width: 380px; margin: 10px; }
.unit-6    { width: 460px; margin: 10px; }
.unit-7    { width: 540px; margin: 10px; }
.unit-8    { width: 620px; margin: 10px; }
.unit-9    { width: 700px; margin: 10px; }
.unit-10   { width: 780px; margin: 10px; }
.unit-11   { width: 860px; margin: 10px; }
.unit-12   { width: 940px; margin: 10px; }




                                                                      19
Inheritance :: Type #2
Init: 960gs, 12units                         Final: 1280gs, 16units
.unit-1    { width: 60px; margin: 10px; }    .unit-1    { width: 60px; margin: 10px; }
.unit-2    { width: 140px; margin: 10px; }   .unit-2    { width: 140px; margin: 10px; }
.unit-3    { width: 220px; margin: 10px; }   .unit-3    { width: 220px; margin: 10px; }
.unit-4    { width: 300px; margin: 10px; }   .unit-4    { width: 300px; margin: 10px; }
.unit-5    { width: 380px; margin: 10px; }   .unit-5    { width: 380px; margin: 10px; }
.unit-6    { width: 460px; margin: 10px; }   .unit-6    { width: 460px; margin: 10px; }
.unit-7    { width: 540px; margin: 10px; }   .unit-7    { width: 540px; margin: 10px; }
.unit-8    { width: 620px; margin: 10px; }   .unit-8    { width: 620px; margin: 10px; }
.unit-9    { width: 700px; margin: 10px; }   .unit-9    { width: 700px; margin: 10px; }
.unit-10   { width: 780px; margin: 10px; }   .unit-10   { width: 780px; margin: 10px; }
.unit-11   { width: 860px; margin: 10px; }   .unit-11   { width: 860px; margin: 10px; }
.unit-12   { width: 940px; margin: 10px; }   .unit-12   { width: 940px; margin: 10px; }




                                                                                    20
Inheritance :: Type #2
Init: 960gs, 12units                         Final: 1280gs, 16units
.unit-1    { width: 60px; margin: 10px; }    .unit-1    { width: 60px; margin: 10px; }
.unit-2    { width: 140px; margin: 10px; }   .unit-2    { width: 140px; margin: 10px; }
.unit-3    { width: 220px; margin: 10px; }   .unit-3    { width: 220px; margin: 10px; }
.unit-4    { width: 300px; margin: 10px; }   .unit-4    { width: 300px; margin: 10px; }
.unit-5    { width: 380px; margin: 10px; }   .unit-5    { width: 380px; margin: 10px; }
.unit-6    { width: 460px; margin: 10px; }   .unit-6    { width: 460px; margin: 10px; }
.unit-7    { width: 540px; margin: 10px; }   .unit-7    { width: 540px; margin: 10px; }
.unit-8    { width: 620px; margin: 10px; }   .unit-8    { width: 620px; margin: 10px; }
.unit-9    { width: 700px; margin: 10px; }   .unit-9    { width: 700px; margin: 10px; }
.unit-10   { width: 780px; margin: 10px; }   .unit-10   { width: 780px; margin: 10px; }
.unit-11   { width: 860px; margin: 10px; }   .unit-11   { width: 860px; margin: 10px; }
.unit-12   { width: 940px; margin: 10px; }   .unit-12   { width: 940px; margin: 10px; }
                                             .unit-13   { width: 1020px; margin: 10px; }
                                             .unit-14   { width: 1100px; margin: 10px; }
                                             .unit-15   { width: 1180px; margin: 10px; }
                                             .unit-16   { width: 1260px; margin: 10px; }


                                                                                    21
Inheritance :: Type #2
Init: 960gs, 12units                         Final: 1280gs, 16units
.unit-1    { width: 60px; margin: 10px; }    .unit-1 { width: 60px; margin: 10px; }
.unit-2    { width: 140px; margin: 10px; }   .unit-2 { width: 140px; margin: 10px; }
.unit-3    { width: 220px; margin: 10px; }   .unit-3 { width: 220px; margin: 10px; }
.unit-4    { width: 300px; margin: 10px; }   .unit-4 { width: 300px; margin: 10px; }
.unit-5    { width: 380px; margin: 10px; }   .unit-5 { width: 380px; margin: 10px; }
.unit-6    { width: 460px; margin: 10px; }   .unit-6 { width: 460px; margin: 10px; }
.unit-7    { width: 540px; margin: 10px; }   .unit-7 { width: 540px; margin: 10px; }
.unit-8    { width: 620px; margin: 10px; }   .unit-8 { width: 620px; margin: 10px; }
.unit-9    { width: 700px; margin: 10px; }   .unit-9 { width: 700px; margin: 10px; }
.unit-10   { width: 780px; margin: 10px; }   .unit-10 { width: 780px; margin: 10px; }
.unit-11   { width: 860px; margin: 10px; }   .unit-11 { width: 860px; margin: 10px; }
.unit-12   { width: 940px; margin: 10px; }   .unit-12 { width: 940px; margin: 10px; }
                                             .unit-13 { width: 1020px; margin: 10px; }
                                             .unit-14 { width: 1100px; margin: 10px; }
                                             .unit-15 { width: 1180px; margin: 10px; }
                                             .unit-16 { width: 1260px; margin: 10px; }
                                             .has-grid-16-units { display: block; }

                                                                                  22
Inheritance :: Type #2
Init: 960gs, 12units                       Final: 1280gs, 16units
.unit-1 { width: 60px; margin: 10px; }     .unit-1 { width: 60px; margin: 10px; }
.unit-2 { width: 140px; margin: 10px; }    .unit-2 { width: 140px; margin: 10px; }
.unit-3 { width: 220px; margin: 10px; }    .unit-3 { width: 220px; margin: 10px; }
.unit-4 { width: 300px; margin: 10px; }    .unit-4 { width: 300px; margin: 10px; }
.unit-5 { width: 380px; margin: 10px; }    .unit-5 { width: 380px; margin: 10px; }
.unit-6 { width: 460px; margin: 10px; }    .unit-6 { width: 460px; margin: 10px; }
.unit-7 { width: 540px; margin: 10px; }    .unit-7 { width: 540px; margin: 10px; }
.unit-8 { width: 620px; margin: 10px; }    .unit-8 { width: 620px; margin: 10px; }
.unit-9 { width: 700px; margin: 10px; }    .unit-9 { width: 700px; margin: 10px; }
.unit-10 { width: 780px; margin: 10px; }   .unit-10 { width: 780px; margin: 10px; }
.unit-11 { width: 860px; margin: 10px; }   .unit-11 { width: 860px; margin: 10px; }
.unit-12 { width: 940px; margin: 10px; }   .unit-12 { width: 940px; margin: 10px; }
.unit-13 { width: 0; margin: 10px; }       .unit-13 { width: 1020px; margin: 10px; }
.unit-14 { width: 0; margin: 10px; }       .unit-14 { width: 1100px; margin: 10px; }
.unit-15 { width: 0; margin: 10px; }       .unit-15 { width: 1180px; margin: 10px; }
.unit-16 { width: 0; margin: 10px; }       .unit-16 { width: 1260px; margin: 10px; }
.has-grid-16-units { display: none; }      .has-grid-16-units { display: block; }

                                                                                23
Inheritance :: Type #2
Init: 960gs, 12units                       Final: 1280gs, 16units
.unit-1 { width: 60px; margin: 10px; }     .unit-1 { width: 60px; margin: 10px; }
.unit-2 { width: 140px; margin: 10px; }    .unit-2 { width: 140px; margin: 10px; }
.unit-3 { width: 220px; margin: 10px; }    .unit-3 { width: 220px; margin: 10px; }
.unit-4 { width: 300px; margin: 10px; }    .unit-4 { width: 300px; margin: 10px; }
.unit-5 { width: 380px; margin: 10px; }    .unit-5 { width: 380px; margin: 10px; }
.unit-6 { width: 460px; margin: 10px; }    .unit-6 { width: 460px; margin: 10px; }
.unit-7 { width: 540px; margin: 10px; }    .unit-7 { width: 540px; margin: 10px; }
.unit-8 { width: 620px; margin: 10px; }    .unit-8 { width: 620px; margin: 10px; }
.unit-9 { width: 700px; margin: 10px; }    .unit-9 { width: 700px; margin: 10px; }
.unit-10 { width: 780px; margin: 10px; }   .unit-10 { width: 780px; margin: 10px; }
.unit-11 { width: 860px; margin: 10px; }   .unit-11 { width: 860px; margin: 10px; }
.unit-12 { width: 940px; margin: 10px; }   .unit-12 { width: 940px; margin: 10px; }
.unit-13 { width: 0; margin: 10px; }       .unit-13 { width: 1020px; margin: 10px; }
.unit-14 { width: 0; margin: 10px; }       .unit-14 { width: 1100px; margin: 10px; }
.unit-15 { width: 0; margin: 10px; }       .unit-15 { width: 1180px; margin: 10px; }
.unit-16 { width: 0; margin: 10px; }       .unit-16 { width: 1260px; margin: 10px; }
.is-big-screen { display: none; }          .is-big-screen { display: block; }

                                                                                24
Inheritance :: Type #2
Init: 960gs, 12units                       Final: 1280gs, 16units
.unit-1 { width: 60px; margin: 10px; }     .unit-1 { width: 60px; margin: 10px; }
.unit-2 { width: 140px; margin: 10px; }    .unit-2 { width: 140px; margin: 10px; }
.unit-3 { width: 220px; margin: 10px; }    .unit-3 { width: 220px; margin: 10px; }
.unit-4 { width: 300px; margin: 10px; }    .unit-4 { width: 300px; margin: 10px; }
.unit-5 { width: 380px; margin: 10px; }    .unit-5 { width: 380px; margin: 10px; }
.unit-6 { width: 460px; margin: 10px; }    .unit-6 { width: 460px; margin: 10px; }
.unit-7 { width: 540px; margin: 10px; }    .unit-7 { width: 540px; margin: 10px; }
.unit-8 { width: 620px; margin: 10px; }    .unit-8 { width: 620px; margin: 10px; }
.unit-9 { width: 700px; margin: 10px; }    .unit-9 { width: 700px; margin: 10px; }
.unit-10 { width: 780px; margin: 10px; }   .unit-10 { width: 780px; margin: 10px; }
.unit-11 { width: 860px; margin: 10px; }   .unit-11 { width: 860px; margin: 10px; }
.unit-12 { width: 940px; margin: 10px; }   .unit-12 { width: 940px; margin: 10px; }
.unit-13 { width: 0; margin: 10px; }       .unit-13 { width: 1020px; margin: 10px; }
.unit-14 { width: 0; margin: 10px; }       .unit-14 { width: 1100px; margin: 10px; }
.unit-15 { width: 0; margin: 10px; }       .unit-15 { width: 1180px; margin: 10px; }
.unit-16 { width: 0; margin: 10px; }       .unit-16 { width: 1260px; margin: 10px; }
.is-big-screen { display: none; }          .is-big-screen { display: block; }

                                                                                25
Polymorphism
.cls1 {
     width: 50%; color: red;
}

.cls1 {
     width: 60%; color: blue;
}

                                26
Polymorphism
#content .cls1 {
   width: 50%; color: red;
}

#sidebar .cls1 {
    width: 60%; color: blue;
}

                               27
Polymorphism
…
     public __construct(Section $section) {
            $this->_section = $section;
     }
     public function print() {
            $this->_section->cls1->render();
     }
..

$dummy = new Dummy(new Content());
$dummy->render();
$dummy = new Dummy(new Sidebar());
$dummy->render();

                                               28
Mixins
.btn {
         /* default value of width,
            e.g. auto or inherit */
}

.small {
       width: 100px;
}

.big {
         width: 700px;
}



                                      29
Mixins
<div class=“btn small”>Small</div>

<div class=“btn big”>Big</div>




                                     30
Aggregation
.box {
      …
}

.box .header {
      …
}

.box > .footer {
     …
}


                           31
Aggregation is
 Polymorphic




                 32
Composition
.box {
      …
}

.box-header {
     …
}

.box-footer {
      …
}


                          33
Namespaces
.page-home        {…}
.page-account     {…}

.page-home .box { … }
.page-account .box { … }




                           34
States
.is-state      {…}
.has-something { … }

.is-hidden         {…}
.has-notifications { … }




                           35
Combine States
with Namespaces




                  36
States
.box { … }
.box-content { … }

.has-notifications { … }
.has-notifications .box { … }




                                37
Use
LESS/Sass




            38
Combine with
 LESS/Sass




               39
Categories in SMACSS




                       40
Categories in SMACSS
Base Rules
Layout Rules
Module Rules
State Rules
Theme Rules




                         41
You can create own
    categories




                     42
Useful Resources
http://oocss.org/
http://smacss.com/
http://cssdoc.net/

+ Google
+ Wikipedia
+ Slideshare

+ Books on CSS

                         43
What are Your Questions
    and Feedback?




                          44
Thank you

Stanislav Usoltsev




                     45

Contenu connexe

En vedette

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

En vedette (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

OOCSS sand SMACSS

  • 1. OOCSS & SMACSS Stanislav Usoltsev
  • 2. Overview • Encapsulation • Inheritance • Polymorphism • Mixins • Aggregation • Composition • Namespaces • States 2
  • 3. Encapsulation <div style=“width: 50%; color: red;”> Inline Styles </div> 3
  • 4. Encapsulation <div style=“width: 50%; color: red;”> Inline Styles </div> <div class=“cls1”> Use .class </div> 4
  • 5. Inheritance .cls1 { width: 50%; color: red; } .subcls1 { /* new properties */ } 5
  • 6. Inheritance :: Type #1 .cls1 { width: 50%; color: red; } /* via classes */ .cls1.subcls1 { … } 6
  • 7. Inheritance :: Type #1 .btns { background: url(„sprite.png‟); } .btns.submit { background-position: -40px 0; } 7
  • 8. Inheritance :: Type #1 class Button { protected $_background; } class ButtonSubmit extends Button { protected $_bg_position_x = 40, $_bg_position_y = 0; } 8
  • 9. Inheritance :: Type #1 0 0 0 0 0 0 0 0 9
  • 10. Inheritance :: Type #1 !important inline #ID .class tag inline #ID .class tag 0 0 0 0 0 0 0 0 10
  • 11. Inheritance :: Type #1 !important inline #ID .class tag inline #ID .class tag 0 0 0 0 0 0 0 0 Bad Practice 11
  • 12. Inheritance :: Type #1 !important inline #ID .class tag inline #ID .class tag 0 0 0 0 0 0 0 0 Bad Practice 12
  • 13. Inheritance :: Type #1 !important inline #ID .class tag inline #ID .class tag 0 0 0 0 0 0 0 0 Don‟t use #ID in OOCSS and SMACSS Use #ID for JavaScript 13
  • 14. Inheritance :: Type #1 !important inline #ID .class tag inline #ID .class tag 0 0 0 0 0 0 0 0 Don‟t use tags in OOCSS and SMACSS Tags - unpredictable 14
  • 15. Inheritance :: Type #1 .btns { .class 1 background: url(„sprite.png‟); } .btns.submit { .class 2 background-position: -40px 0; } + cascade 15
  • 16. Inheritance :: Type #2 .cls1 { width: 50%; color: red; } /* via media queries */ @media … { … } 16
  • 17. Inheritance :: Type #2 Init: 960gs, 12units 17
  • 18. Inheritance :: Type #2 Init: 960gs, 12units .unit-1 { width: 60px; margin: 10px; } .unit-2 { width: 140px; margin: 10px; } .unit-3 { width: 220px; margin: 10px; } .unit-4 { width: 300px; margin: 10px; } .unit-5 { width: 380px; margin: 10px; } .unit-6 { width: 460px; margin: 10px; } .unit-7 { width: 540px; margin: 10px; } .unit-8 { width: 620px; margin: 10px; } .unit-9 { width: 700px; margin: 10px; } .unit-10 { width: 780px; margin: 10px; } .unit-11 { width: 860px; margin: 10px; } .unit-12 { width: 940px; margin: 10px; } 18
  • 19. Inheritance :: Type #2 Init: 960gs, 12units Final: 1280gs, 16units .unit-1 { width: 60px; margin: 10px; } .unit-2 { width: 140px; margin: 10px; } .unit-3 { width: 220px; margin: 10px; } .unit-4 { width: 300px; margin: 10px; } .unit-5 { width: 380px; margin: 10px; } .unit-6 { width: 460px; margin: 10px; } .unit-7 { width: 540px; margin: 10px; } .unit-8 { width: 620px; margin: 10px; } .unit-9 { width: 700px; margin: 10px; } .unit-10 { width: 780px; margin: 10px; } .unit-11 { width: 860px; margin: 10px; } .unit-12 { width: 940px; margin: 10px; } 19
  • 20. Inheritance :: Type #2 Init: 960gs, 12units Final: 1280gs, 16units .unit-1 { width: 60px; margin: 10px; } .unit-1 { width: 60px; margin: 10px; } .unit-2 { width: 140px; margin: 10px; } .unit-2 { width: 140px; margin: 10px; } .unit-3 { width: 220px; margin: 10px; } .unit-3 { width: 220px; margin: 10px; } .unit-4 { width: 300px; margin: 10px; } .unit-4 { width: 300px; margin: 10px; } .unit-5 { width: 380px; margin: 10px; } .unit-5 { width: 380px; margin: 10px; } .unit-6 { width: 460px; margin: 10px; } .unit-6 { width: 460px; margin: 10px; } .unit-7 { width: 540px; margin: 10px; } .unit-7 { width: 540px; margin: 10px; } .unit-8 { width: 620px; margin: 10px; } .unit-8 { width: 620px; margin: 10px; } .unit-9 { width: 700px; margin: 10px; } .unit-9 { width: 700px; margin: 10px; } .unit-10 { width: 780px; margin: 10px; } .unit-10 { width: 780px; margin: 10px; } .unit-11 { width: 860px; margin: 10px; } .unit-11 { width: 860px; margin: 10px; } .unit-12 { width: 940px; margin: 10px; } .unit-12 { width: 940px; margin: 10px; } 20
  • 21. Inheritance :: Type #2 Init: 960gs, 12units Final: 1280gs, 16units .unit-1 { width: 60px; margin: 10px; } .unit-1 { width: 60px; margin: 10px; } .unit-2 { width: 140px; margin: 10px; } .unit-2 { width: 140px; margin: 10px; } .unit-3 { width: 220px; margin: 10px; } .unit-3 { width: 220px; margin: 10px; } .unit-4 { width: 300px; margin: 10px; } .unit-4 { width: 300px; margin: 10px; } .unit-5 { width: 380px; margin: 10px; } .unit-5 { width: 380px; margin: 10px; } .unit-6 { width: 460px; margin: 10px; } .unit-6 { width: 460px; margin: 10px; } .unit-7 { width: 540px; margin: 10px; } .unit-7 { width: 540px; margin: 10px; } .unit-8 { width: 620px; margin: 10px; } .unit-8 { width: 620px; margin: 10px; } .unit-9 { width: 700px; margin: 10px; } .unit-9 { width: 700px; margin: 10px; } .unit-10 { width: 780px; margin: 10px; } .unit-10 { width: 780px; margin: 10px; } .unit-11 { width: 860px; margin: 10px; } .unit-11 { width: 860px; margin: 10px; } .unit-12 { width: 940px; margin: 10px; } .unit-12 { width: 940px; margin: 10px; } .unit-13 { width: 1020px; margin: 10px; } .unit-14 { width: 1100px; margin: 10px; } .unit-15 { width: 1180px; margin: 10px; } .unit-16 { width: 1260px; margin: 10px; } 21
  • 22. Inheritance :: Type #2 Init: 960gs, 12units Final: 1280gs, 16units .unit-1 { width: 60px; margin: 10px; } .unit-1 { width: 60px; margin: 10px; } .unit-2 { width: 140px; margin: 10px; } .unit-2 { width: 140px; margin: 10px; } .unit-3 { width: 220px; margin: 10px; } .unit-3 { width: 220px; margin: 10px; } .unit-4 { width: 300px; margin: 10px; } .unit-4 { width: 300px; margin: 10px; } .unit-5 { width: 380px; margin: 10px; } .unit-5 { width: 380px; margin: 10px; } .unit-6 { width: 460px; margin: 10px; } .unit-6 { width: 460px; margin: 10px; } .unit-7 { width: 540px; margin: 10px; } .unit-7 { width: 540px; margin: 10px; } .unit-8 { width: 620px; margin: 10px; } .unit-8 { width: 620px; margin: 10px; } .unit-9 { width: 700px; margin: 10px; } .unit-9 { width: 700px; margin: 10px; } .unit-10 { width: 780px; margin: 10px; } .unit-10 { width: 780px; margin: 10px; } .unit-11 { width: 860px; margin: 10px; } .unit-11 { width: 860px; margin: 10px; } .unit-12 { width: 940px; margin: 10px; } .unit-12 { width: 940px; margin: 10px; } .unit-13 { width: 1020px; margin: 10px; } .unit-14 { width: 1100px; margin: 10px; } .unit-15 { width: 1180px; margin: 10px; } .unit-16 { width: 1260px; margin: 10px; } .has-grid-16-units { display: block; } 22
  • 23. Inheritance :: Type #2 Init: 960gs, 12units Final: 1280gs, 16units .unit-1 { width: 60px; margin: 10px; } .unit-1 { width: 60px; margin: 10px; } .unit-2 { width: 140px; margin: 10px; } .unit-2 { width: 140px; margin: 10px; } .unit-3 { width: 220px; margin: 10px; } .unit-3 { width: 220px; margin: 10px; } .unit-4 { width: 300px; margin: 10px; } .unit-4 { width: 300px; margin: 10px; } .unit-5 { width: 380px; margin: 10px; } .unit-5 { width: 380px; margin: 10px; } .unit-6 { width: 460px; margin: 10px; } .unit-6 { width: 460px; margin: 10px; } .unit-7 { width: 540px; margin: 10px; } .unit-7 { width: 540px; margin: 10px; } .unit-8 { width: 620px; margin: 10px; } .unit-8 { width: 620px; margin: 10px; } .unit-9 { width: 700px; margin: 10px; } .unit-9 { width: 700px; margin: 10px; } .unit-10 { width: 780px; margin: 10px; } .unit-10 { width: 780px; margin: 10px; } .unit-11 { width: 860px; margin: 10px; } .unit-11 { width: 860px; margin: 10px; } .unit-12 { width: 940px; margin: 10px; } .unit-12 { width: 940px; margin: 10px; } .unit-13 { width: 0; margin: 10px; } .unit-13 { width: 1020px; margin: 10px; } .unit-14 { width: 0; margin: 10px; } .unit-14 { width: 1100px; margin: 10px; } .unit-15 { width: 0; margin: 10px; } .unit-15 { width: 1180px; margin: 10px; } .unit-16 { width: 0; margin: 10px; } .unit-16 { width: 1260px; margin: 10px; } .has-grid-16-units { display: none; } .has-grid-16-units { display: block; } 23
  • 24. Inheritance :: Type #2 Init: 960gs, 12units Final: 1280gs, 16units .unit-1 { width: 60px; margin: 10px; } .unit-1 { width: 60px; margin: 10px; } .unit-2 { width: 140px; margin: 10px; } .unit-2 { width: 140px; margin: 10px; } .unit-3 { width: 220px; margin: 10px; } .unit-3 { width: 220px; margin: 10px; } .unit-4 { width: 300px; margin: 10px; } .unit-4 { width: 300px; margin: 10px; } .unit-5 { width: 380px; margin: 10px; } .unit-5 { width: 380px; margin: 10px; } .unit-6 { width: 460px; margin: 10px; } .unit-6 { width: 460px; margin: 10px; } .unit-7 { width: 540px; margin: 10px; } .unit-7 { width: 540px; margin: 10px; } .unit-8 { width: 620px; margin: 10px; } .unit-8 { width: 620px; margin: 10px; } .unit-9 { width: 700px; margin: 10px; } .unit-9 { width: 700px; margin: 10px; } .unit-10 { width: 780px; margin: 10px; } .unit-10 { width: 780px; margin: 10px; } .unit-11 { width: 860px; margin: 10px; } .unit-11 { width: 860px; margin: 10px; } .unit-12 { width: 940px; margin: 10px; } .unit-12 { width: 940px; margin: 10px; } .unit-13 { width: 0; margin: 10px; } .unit-13 { width: 1020px; margin: 10px; } .unit-14 { width: 0; margin: 10px; } .unit-14 { width: 1100px; margin: 10px; } .unit-15 { width: 0; margin: 10px; } .unit-15 { width: 1180px; margin: 10px; } .unit-16 { width: 0; margin: 10px; } .unit-16 { width: 1260px; margin: 10px; } .is-big-screen { display: none; } .is-big-screen { display: block; } 24
  • 25. Inheritance :: Type #2 Init: 960gs, 12units Final: 1280gs, 16units .unit-1 { width: 60px; margin: 10px; } .unit-1 { width: 60px; margin: 10px; } .unit-2 { width: 140px; margin: 10px; } .unit-2 { width: 140px; margin: 10px; } .unit-3 { width: 220px; margin: 10px; } .unit-3 { width: 220px; margin: 10px; } .unit-4 { width: 300px; margin: 10px; } .unit-4 { width: 300px; margin: 10px; } .unit-5 { width: 380px; margin: 10px; } .unit-5 { width: 380px; margin: 10px; } .unit-6 { width: 460px; margin: 10px; } .unit-6 { width: 460px; margin: 10px; } .unit-7 { width: 540px; margin: 10px; } .unit-7 { width: 540px; margin: 10px; } .unit-8 { width: 620px; margin: 10px; } .unit-8 { width: 620px; margin: 10px; } .unit-9 { width: 700px; margin: 10px; } .unit-9 { width: 700px; margin: 10px; } .unit-10 { width: 780px; margin: 10px; } .unit-10 { width: 780px; margin: 10px; } .unit-11 { width: 860px; margin: 10px; } .unit-11 { width: 860px; margin: 10px; } .unit-12 { width: 940px; margin: 10px; } .unit-12 { width: 940px; margin: 10px; } .unit-13 { width: 0; margin: 10px; } .unit-13 { width: 1020px; margin: 10px; } .unit-14 { width: 0; margin: 10px; } .unit-14 { width: 1100px; margin: 10px; } .unit-15 { width: 0; margin: 10px; } .unit-15 { width: 1180px; margin: 10px; } .unit-16 { width: 0; margin: 10px; } .unit-16 { width: 1260px; margin: 10px; } .is-big-screen { display: none; } .is-big-screen { display: block; } 25
  • 26. Polymorphism .cls1 { width: 50%; color: red; } .cls1 { width: 60%; color: blue; } 26
  • 27. Polymorphism #content .cls1 { width: 50%; color: red; } #sidebar .cls1 { width: 60%; color: blue; } 27
  • 28. Polymorphism … public __construct(Section $section) { $this->_section = $section; } public function print() { $this->_section->cls1->render(); } .. $dummy = new Dummy(new Content()); $dummy->render(); $dummy = new Dummy(new Sidebar()); $dummy->render(); 28
  • 29. Mixins .btn { /* default value of width, e.g. auto or inherit */ } .small { width: 100px; } .big { width: 700px; } 29
  • 30. Mixins <div class=“btn small”>Small</div> <div class=“btn big”>Big</div> 30
  • 31. Aggregation .box { … } .box .header { … } .box > .footer { … } 31
  • 33. Composition .box { … } .box-header { … } .box-footer { … } 33
  • 34. Namespaces .page-home {…} .page-account {…} .page-home .box { … } .page-account .box { … } 34
  • 35. States .is-state {…} .has-something { … } .is-hidden {…} .has-notifications { … } 35
  • 37. States .box { … } .box-content { … } .has-notifications { … } .has-notifications .box { … } 37
  • 41. Categories in SMACSS Base Rules Layout Rules Module Rules State Rules Theme Rules 41
  • 42. You can create own categories 42
  • 44. What are Your Questions and Feedback? 44