OUR BEST PRACTICES ARE               KILLING US  photo by Joshua Stearns                            Nicole SullivanWednesd...
WHAT WE WILL COVER:    ❖   We have a problem    ❖   CSS is not to blame    ❖   Tools won’t solve it, but they can helpWedn...
YUMMY DATA FROM                          FACEBOOKWednesday, March 30, 2011
FACEBOOK BLUE                             261Wednesday, March 30, 2011
UNIQUE COLORS                             548                               unique hex values                             ...
COLORS                            6498                            color declarations                                      ...
YUMMY DATA FROM                          SALESFORCEWednesday, March 30, 2011
paddingWednesday, March 30, 2011
3,668                             padding declarationsWednesday, March 30, 2011
ARE NICOLE’S CLIENTS             EXCEPTIONALLY MESSY?Wednesday, March 30, 2011
ALEXA TOP 1000 STUDY                            with Stoyan StefanovWednesday, March 30, 2011
h1-h6Wednesday, March 30, 2011
511                            declarations setting styles for h1-h6  56% >10  9% >100Wednesday, March 30, 2011
!importantWednesday, March 30, 2011
!IMPORTANT                             518                            declarations using important 12% have greater than 5...
floatWednesday, March 30, 2011
733                            declarations floated elements  56% > 10 13% > 100Wednesday, March 30, 2011
font-sizeWednesday, March 30, 2011
FONT-SIZE                               889                            declarations changed the font-size 78% >10 23% >100...
DOES THIS APPLY TO YOU?                   Do your websites have the same issues? WorkshopWednesday, March 30, 2011
SO, DUPLICATION IS A                     PROBLEM AT:    ❖   Facebook    ❖   Salesforce    ❖   w3c    ❖   Box.net    ❖   th...
INSANITY:                            doing the same thing over and over                              and expecting differe...
STOP POINTING FINGERS                            the truth is, we all have this problem                                  h...
“JAVASCRIPT DOESN’T SUCK                      You’re just doing it wrong.” -- Douglas CrockfordWednesday, March 30, 2011
CSS         “JAVASCRIPT DOESN’T SUCK                      You’re just doing it wrong.” -- Douglas CrockfordWednesday, Marc...
ABOUT CSS                            CSS (much like JS) will let                                you do anything           ...
THE POINT               IS...       That we don’t have to do       stupid things, just because                 we can.Wedn...
SO, WHAT ARE THE STUPID            THINGS?                            Best Practice MythsWednesday, March 30, 2011
THREE BEST PRACTICE                          MYTHS:    ❖   Don’t add any extra elements    ❖   Don’t add classes (Classiti...
WHAT HAPPENS NEXT?                 SPECIFICITY WARSWednesday, March 30, 2011
SPECIFICITY - THE SIMPLE                   VERSIONWednesday, March 30, 2011
SPECIFICITY - THE SIMPLE                   VERSION                                elements                               &...
SPECIFICITY - THE SIMPLE                   VERSION                              classes           elements                ...
SPECIFICITY - THE SIMPLE                   VERSION                            IDs     classes           elements          ...
SPECIFICITY - THE SIMPLE                   VERSION             inline         IDs     classes           elements          ...
SPECIFICITY - THE SIMPLE                   VERSION                #sidebar ul li a.myclass:hover{}             inline     ...
SPECIFICITY - THE SIMPLE                   VERSION                #sidebar ul li a.myclass:hover{}             inline     ...
SPECIFICITY - THE SIMPLE                   VERSION                #sidebar ul li a.myclass:hover{}             inline     ...
SPECIFICITY - THE SIMPLE                   VERSION                #sidebar ul li a.myclass:hover{}             inline     ...
SPECIFICITY - THE SIMPLE                   VERSION                #sidebar ul li a.myclass:hover{}             inline     ...
SPECIFICITY - THE SIMPLE                   VERSION                #sidebar ul li a.myclass:hover{}             inline     ...
UNIVERSAL SELECTOR                                  * {}             inline         IDs          classes         elements ...
UNIVERSAL SELECTOR                                  * {}             inline         IDs          classes         elements ...
UNIVERSAL SELECTOR                                  * {}             inline         IDs          classes         elements ...
UNIVERSAL SELECTOR                                  * {}             inline         IDs          classes         elements ...
UNIVERSAL SELECTOR                                  * {}             inline         IDs          classes         elements ...
CONCATENATING                              SPECIFICITY                      .item{color: blue;}                      ul li...
CONCATENATING                              SPECIFICITY                      .item{color: blue;}                      ul li...
CONCATENATING                              SPECIFICITY                      .item{color: blue;}                      ul li...
CONCATENATING                              SPECIFICITY                      .item{color: blue;}                      ul li...
CONCATENATING                              SPECIFICITY                      .item{color: blue;}                      ul li...
CONCATENATING                              SPECIFICITY                      .item{color: blue;}                      ul li...
CONCATENATING                              SPECIFICITY                      .item{color: blue;}                      ul li...
CONCATENATING                              SPECIFICITY                      .item{color: blue;}                      ul li...
CONCATENATING                              SPECIFICITY                      .item{color: blue;}                      ul li...
CONCATENATING                              SPECIFICITY                      .item{color: blue;}                      ul li...
CLASS ORDER                  <p class=”message error”>Borken!</p>Wednesday, March 30, 2011
CLASS ORDER                    The order of the classes makes no difference.                  <p class=”message error”>Bor...
SITE-WIDE HEADINGS                     h1{color:   #333;   font-size:   24px;   font-weight:   bold}                     h...
SITE-WIDE HEADINGS                     h1{color:   #333;   font-size:   24px;   font-weight:   bold}                     h...
SITE-WIDE HEADINGS                     h1{color:   #333;   font-size:   24px;   font-weight:   bold}                     h...
SITE-WIDE HEADINGS                     h1{color:   #333;   font-size:   24px;   font-weight:   bold}                     h...
SITE-WIDE HEADINGS                     h1{color:   #333;   font-size:   24px;   font-weight:   bold}                     h...
#sidebarWednesday, March 30, 2011
h3 {                              color: #797979;                              font-size: 12px;                           ...
HOW DO YOU GET THE H3       TO LOOK DIFFERENT?                                   (but only in the sidebar)                ...
#SIDEBAR H3      h1{color: #333; font-size: 24px; font-weight: bold}      h2{color: #333; font-size: 19px; font-weight: bo...
THEN, YOUR DESIGNER      GIVES YOU A NEW MOCK                            h3 {                              color: #555;   ...
ADD IT TO THE STYLESHEET             h1{color: #333; font-size: 24px; font-weight: bold}             h2{color: #333; font-...
WHAT IS HAPPENING WITH       THE SPECIFICITY?      h3{...}      #sidebar h3{...}      #sidebar .account h3{...}Wednesday, ...
WHAT IS HAPPENING WITH       THE SPECIFICITY?      h3{...}                     0   0   0   1      #sidebar h3{...}      #s...
WHAT IS HAPPENING WITH       THE SPECIFICITY?      h3{...}                     0   0   0   1      #sidebar h3{...}        ...
WHAT IS HAPPENING WITH       THE SPECIFICITY?      h3{...}                     0   0   0   1      #sidebar h3{...}        ...
THE SITE HAS A WEATHER         MODULE IN THE SIDEBAR                            h2                                        ...
IMAGINE YOU RECEIVED              THIS WIREFRAME                                                            h3            ...
IMAGINE YOU RECEIVED              THIS WIREFRAME                                                                   h3     ...
NOTICE ANYTHING ABOUT     NESTING & SPECIFICITY?                                                            h3            ...
NOTICE ANYTHING ABOUT     NESTING & SPECIFICITY?                                                                h3        ...
NOTICE ANYTHING ABOUT     NESTING & SPECIFICITY?                                                                h3        ...
SIX MONTHS LATER, IT                   GETS COMPLICATED    ❖   Specificity grows over time    ❖   Difficult to tell which ru...
WHAT HAPPENS WHEN...      there are no more ways to make a rule more specific than the                    one you are tryin...
<h3 style=”color: red; font-weight: bold; font-size: 20px;”>My     shiny new heading level 3</h3>          WHAT HAPPENS WH...
<h3 style=”color: red; font-weight: bold; font-size: 20px;”>My     shiny new heading level 3</h3>          WHAT HAPPENS WH...
AND THEN ANOTHER                     DEVELOPER SAYS...                     “this is gross! we should not be using inline-s...
#sidebar .weatherMod .hourly .tuesday h3{color: blue !important;}          YOU MIGHT THINK       !IMPORTANT WOULD END     ...
#sidebar .weatherMod .hourly .tuesday h3{color: blue !important;}          YOU MIGHT THINK       !IMPORTANT WOULD END     ...
#sidebar .weatherMod .hourly .tuesday h3{color: blue !important;}          YOU MIGHT THINK       !IMPORTANT WOULD END     ...
#sidebar .weatherMod .hourly .tuesday h3{color: blue !important;}          YOU MIGHT THINK       !IMPORTANT WOULD END     ...
HOSTILE CODE                            ENVIRONMENT    ❖   Two layers develop    ❖   Specificity grows over time (more and ...
SPECIFICITY AT IT’S WORST                            normal                                       IDs                     ...
SPECIFICITY AT IT’S WORST                             inline   Inline Styles                            normal            ...
SPECIFICITY AT IT’S WORST                      !important          IDs                                        Classes     ...
#sidebar                            A Normal Heading Level 3Wednesday, March 30, 2011
DUPLICATING PROPERTY                 VALUE PAIRS      h1{ margin: 10px 0; color: #333; font-size: 24px; font-weight: bold}...
THREE PROBLEMS    ❖   Duplication of property value pairs    ❖   Duplication of elements (h3)    ❖   Growing SpecificityWed...
DUPLICATING ELEMENTS      h1{}      h2{}      h3{}      #sidebar              .collaborators h3{}      #sidebar           ...
GROWING SPECIFICITY      h1{}      h2{}      h3{}      #sidebar              .collaborators h3{}      #sidebar            ...
HOW DO WE SOLVE THESE          PROBLEMS?                      Examine our best practice myths rationally    ❖   Add non-se...
MEDIA BLOCK EXAMPLEWednesday, March 30, 2011
ALL OF THESE ARE THE                      SAME OBJECTWednesday, March 30, 2011
WHAT DO WE KNOW?                            ❖ Can be nested                            ❖ Optional right button            ...
WHAT DON’T WE KNOW?                            ❖ Image width and decoration vary                            ❖ Right conten...
SEPARATE STRUCTURE                       FROM CHROMEWednesday, March 30, 2011
A FEW LINES OF HTML...            <div class="media attribution">              <a href="http://twitter.com/stubbornella" c...
4 LINES OF CSS...                                  _Wednesday, March 30, 2011
Wednesday, March 30, 2011
HTML SIZE                     reduced by 50%                                  by Stefan ParkerWednesday, March 30, 2011
“Due to these efforts, we cut our average           CSS bytes per page by 19% (after gzip) and           HTML bytes per pa...
Wednesday, March 30, 2011
GREAT DEVELOPERS CAN          BUILD AMAZING THINGS                        if we move worst-best practices out of our wayWe...
LET’S KEEP TALKING...                                 www.stubbornella.org                                   @stubbornella...
Upcoming SlideShare
Loading in...5
×

Our Best Practices Are Killing Us

135,917

Published on

We keep thinking we can write better CSS if we just try harder, that the next site will be clean and stay that way. This presentation shows that in fact, messy CSS is the direct result of our worst best-practices. We need to reexamine those assumptions with an eye to practicality and scalability as well as accessibility, standards, and fabulous design.

Published in: Technology
22 Comments
333 Likes
Statistics
Notes
No Downloads
Views
Total Views
135,917
On Slideshare
0
From Embeds
0
Number of Embeds
63
Actions
Shares
0
Downloads
0
Comments
22
Likes
333
Embeds 0
No embeds

No notes for slide

Our Best Practices Are Killing Us

  1. 1. OUR BEST PRACTICES ARE KILLING US photo by Joshua Stearns Nicole SullivanWednesday, March 30, 2011
  2. 2. WHAT WE WILL COVER: ❖ We have a problem ❖ CSS is not to blame ❖ Tools won’t solve it, but they can helpWednesday, March 30, 2011
  3. 3. YUMMY DATA FROM FACEBOOKWednesday, March 30, 2011
  4. 4. FACEBOOK BLUE 261Wednesday, March 30, 2011
  5. 5. UNIQUE COLORS 548 unique hex values FacebookWednesday, March 30, 2011
  6. 6. COLORS 6498 color declarations FacebookWednesday, March 30, 2011
  7. 7. YUMMY DATA FROM SALESFORCEWednesday, March 30, 2011
  8. 8. paddingWednesday, March 30, 2011
  9. 9. 3,668 padding declarationsWednesday, March 30, 2011
  10. 10. ARE NICOLE’S CLIENTS EXCEPTIONALLY MESSY?Wednesday, March 30, 2011
  11. 11. ALEXA TOP 1000 STUDY with Stoyan StefanovWednesday, March 30, 2011
  12. 12. h1-h6Wednesday, March 30, 2011
  13. 13. 511 declarations setting styles for h1-h6 56% >10 9% >100Wednesday, March 30, 2011
  14. 14. !importantWednesday, March 30, 2011
  15. 15. !IMPORTANT 518 declarations using important 12% have greater than 50Wednesday, March 30, 2011
  16. 16. floatWednesday, March 30, 2011
  17. 17. 733 declarations floated elements 56% > 10 13% > 100Wednesday, March 30, 2011
  18. 18. font-sizeWednesday, March 30, 2011
  19. 19. FONT-SIZE 889 declarations changed the font-size 78% >10 23% >100Wednesday, March 30, 2011
  20. 20. DOES THIS APPLY TO YOU? Do your websites have the same issues? WorkshopWednesday, March 30, 2011
  21. 21. SO, DUPLICATION IS A PROBLEM AT: ❖ Facebook ❖ Salesforce ❖ w3c ❖ Box.net ❖ the Alexa Top 1000 sites ❖ Government websites ❖ Small and large businessesWednesday, March 30, 2011
  22. 22. INSANITY: doing the same thing over and over and expecting different resultsWednesday, March 30, 2011
  23. 23. STOP POINTING FINGERS the truth is, we all have this problem http://www.flickr.com/photos/illumiquest/2749137895/sizes/l/in/photostream/Wednesday, March 30, 2011
  24. 24. “JAVASCRIPT DOESN’T SUCK You’re just doing it wrong.” -- Douglas CrockfordWednesday, March 30, 2011
  25. 25. CSS “JAVASCRIPT DOESN’T SUCK You’re just doing it wrong.” -- Douglas CrockfordWednesday, March 30, 2011
  26. 26. ABOUT CSS CSS (much like JS) will let you do anything (no matter how stupid) wheeee!Wednesday, March 30, 2011
  27. 27. THE POINT IS... That we don’t have to do stupid things, just because we can.Wednesday, March 30, 2011
  28. 28. SO, WHAT ARE THE STUPID THINGS? Best Practice MythsWednesday, March 30, 2011
  29. 29. THREE BEST PRACTICE MYTHS: ❖ Don’t add any extra elements ❖ Don’t add classes (Classitis! Ahhh!) ❖ Use descendent selectors exclusivelyWednesday, March 30, 2011
  30. 30. WHAT HAPPENS NEXT? SPECIFICITY WARSWednesday, March 30, 2011
  31. 31. SPECIFICITY - THE SIMPLE VERSIONWednesday, March 30, 2011
  32. 32. SPECIFICITY - THE SIMPLE VERSION elements & pseudo elementsWednesday, March 30, 2011
  33. 33. SPECIFICITY - THE SIMPLE VERSION classes elements & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  34. 34. SPECIFICITY - THE SIMPLE VERSION IDs classes elements & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  35. 35. SPECIFICITY - THE SIMPLE VERSION inline IDs classes elements & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  36. 36. SPECIFICITY - THE SIMPLE VERSION #sidebar ul li a.myclass:hover{} inline IDs classes elements & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  37. 37. SPECIFICITY - THE SIMPLE VERSION #sidebar ul li a.myclass:hover{} inline IDs classes elements 3 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  38. 38. SPECIFICITY - THE SIMPLE VERSION #sidebar ul li a.myclass:hover{} inline IDs classes elements 2 3 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  39. 39. SPECIFICITY - THE SIMPLE VERSION #sidebar ul li a.myclass:hover{} inline IDs classes elements 1 2 3 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  40. 40. SPECIFICITY - THE SIMPLE VERSION #sidebar ul li a.myclass:hover{} inline IDs classes elements 0 1 2 3 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  41. 41. SPECIFICITY - THE SIMPLE VERSION #sidebar ul li a.myclass:hover{} inline IDs classes elements 0 1 2 3 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  42. 42. UNIVERSAL SELECTOR * {} inline IDs classes elements & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  43. 43. UNIVERSAL SELECTOR * {} inline IDs classes elements 0 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  44. 44. UNIVERSAL SELECTOR * {} inline IDs classes elements 0 0 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  45. 45. UNIVERSAL SELECTOR * {} inline IDs classes elements 0 0 0 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  46. 46. UNIVERSAL SELECTOR * {} inline IDs classes elements 0 0 0 0 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  47. 47. CONCATENATING SPECIFICITY .item{color: blue;} ul li li li li li li li li li{color: red;} inline IDs classes elements & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  48. 48. CONCATENATING SPECIFICITY .item{color: blue;} ul li li li li li li li li li{color: red;} inline IDs classes elements 0 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  49. 49. CONCATENATING SPECIFICITY .item{color: blue;} ul li li li li li li li li li{color: red;} inline IDs classes elements 1 0 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  50. 50. CONCATENATING SPECIFICITY .item{color: blue;} ul li li li li li li li li li{color: red;} inline IDs classes elements 0 1 0 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  51. 51. CONCATENATING SPECIFICITY .item{color: blue;} ul li li li li li li li li li{color: red;} inline IDs classes elements 0 0 1 0 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  52. 52. CONCATENATING SPECIFICITY .item{color: blue;} ul li li li li li li li li li{color: red;} inline IDs classes elements & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  53. 53. CONCATENATING SPECIFICITY .item{color: blue;} ul li li li li li li li li li{color: red;} inline IDs classes elements 10 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  54. 54. CONCATENATING SPECIFICITY .item{color: blue;} ul li li li li li li li li li{color: red;} inline IDs classes elements 0 10 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  55. 55. CONCATENATING SPECIFICITY .item{color: blue;} ul li li li li li li li li li{color: red;} inline IDs classes elements 0 0 10 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  56. 56. CONCATENATING SPECIFICITY .item{color: blue;} ul li li li li li li li li li{color: red;} inline IDs classes elements 0 0 0 10 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  57. 57. CLASS ORDER <p class=”message error”>Borken!</p>Wednesday, March 30, 2011
  58. 58. CLASS ORDER The order of the classes makes no difference. <p class=”message error”>Borken!</p>Wednesday, March 30, 2011
  59. 59. SITE-WIDE HEADINGS h1{color: #333; font-size: 24px; font-weight: bold} h2{color: #333; font-size: 19px; font-weight: bold} h3{color: #333; font-size: 17px; font-weight: bold} h4{color: #333; font-size: 15px; font-weight: bold} h5{color: #111; font-size: 13px; font-weight: bold} h6{color: #111; font-size: 12px; font-weight: bold} inline IDs classes elements & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  60. 60. SITE-WIDE HEADINGS h1{color: #333; font-size: 24px; font-weight: bold} h2{color: #333; font-size: 19px; font-weight: bold} h3{color: #333; font-size: 17px; font-weight: bold} h4{color: #333; font-size: 15px; font-weight: bold} h5{color: #111; font-size: 13px; font-weight: bold} h6{color: #111; font-size: 12px; font-weight: bold} inline IDs classes elements 1 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  61. 61. SITE-WIDE HEADINGS h1{color: #333; font-size: 24px; font-weight: bold} h2{color: #333; font-size: 19px; font-weight: bold} h3{color: #333; font-size: 17px; font-weight: bold} h4{color: #333; font-size: 15px; font-weight: bold} h5{color: #111; font-size: 13px; font-weight: bold} h6{color: #111; font-size: 12px; font-weight: bold} inline IDs classes elements 0 1 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  62. 62. SITE-WIDE HEADINGS h1{color: #333; font-size: 24px; font-weight: bold} h2{color: #333; font-size: 19px; font-weight: bold} h3{color: #333; font-size: 17px; font-weight: bold} h4{color: #333; font-size: 15px; font-weight: bold} h5{color: #111; font-size: 13px; font-weight: bold} h6{color: #111; font-size: 12px; font-weight: bold} inline IDs classes elements 0 0 1 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  63. 63. SITE-WIDE HEADINGS h1{color: #333; font-size: 24px; font-weight: bold} h2{color: #333; font-size: 19px; font-weight: bold} h3{color: #333; font-size: 17px; font-weight: bold} h4{color: #333; font-size: 15px; font-weight: bold} h5{color: #111; font-size: 13px; font-weight: bold} h6{color: #111; font-size: 12px; font-weight: bold} inline IDs classes elements 0 0 0 1 & pseudo classes & pseudo elements & attributesWednesday, March 30, 2011
  64. 64. #sidebarWednesday, March 30, 2011
  65. 65. h3 { color: #797979; font-size: 12px; font-weight: bold; border-bottom: 1px solid #c5c5c5; padding-bottom: 5px; }Wednesday, March 30, 2011
  66. 66. HOW DO YOU GET THE H3 TO LOOK DIFFERENT? (but only in the sidebar) (and using the semantically appropriate heading)Wednesday, March 30, 2011
  67. 67. #SIDEBAR H3 h1{color: #333; font-size: 24px; font-weight: bold} h2{color: #333; font-size: 19px; font-weight: bold} h3{color: #333; font-size: 17px; font-weight: bold} #sidebar h3 { color: #797979; font-size: 12px;font-weight: bold; border-bottom: 1px solid #c5c5c5; padding-bottom: 5px; } h4{color: #333; font-size: 15px; font-weight: bold} h5{color: #111; font-size: 13px; font-weight: bold} h6{color: #111; font-size: 12px; font-weight: bold}Wednesday, March 30, 2011
  68. 68. THEN, YOUR DESIGNER GIVES YOU A NEW MOCK h3 { color: #555; font-size: 13px; font-weight: bold; background-color: #deeef8; padding: 5px; margin: 10px 0; }Wednesday, March 30, 2011
  69. 69. ADD IT TO THE STYLESHEET h1{color: #333; font-size: 24px; font-weight: bold} h2{color: #333; font-size: 19px; font-weight: bold} h3{color: #333; font-size: 17px; font-weight: bold} #sidebar h3{ color: #797979; font-size: 12px; font-weight: bold; border-bottom: 1px solid #c5c5c5; padding-bottom: 5px; } #sidebar .account h3{ color: #555; font-size: 13px; font-weight: bold; background-color: #deeef8; padding: 5px; margin: 10px 0; } h4{color: #333; font-size: 15px; font-weight: bold} h5{color: #111; font-size: 13px; font-weight: bold} h6{color: #111; font-size: 12px; font-weight: bold}Wednesday, March 30, 2011
  70. 70. WHAT IS HAPPENING WITH THE SPECIFICITY? h3{...} #sidebar h3{...} #sidebar .account h3{...}Wednesday, March 30, 2011
  71. 71. WHAT IS HAPPENING WITH THE SPECIFICITY? h3{...} 0 0 0 1 #sidebar h3{...} #sidebar .account h3{...}Wednesday, March 30, 2011
  72. 72. WHAT IS HAPPENING WITH THE SPECIFICITY? h3{...} 0 0 0 1 #sidebar h3{...} 0 1 0 1 #sidebar .account h3{...}Wednesday, March 30, 2011
  73. 73. WHAT IS HAPPENING WITH THE SPECIFICITY? h3{...} 0 0 0 1 #sidebar h3{...} 0 1 0 1 #sidebar .account h3{...} 0 1 1 1Wednesday, March 30, 2011
  74. 74. THE SITE HAS A WEATHER MODULE IN THE SIDEBAR h2 h3 #sidebar .weatherMod h3{ color: #fff; text-transform: uppercase; }Wednesday, March 30, 2011
  75. 75. IMAGINE YOU RECEIVED THIS WIREFRAME h3 MORN NOON EVENING NIGHT h3 27° 35° 38° 30°Wednesday, March 30, 2011
  76. 76. IMAGINE YOU RECEIVED THIS WIREFRAME h3 MORN NOON EVENING NIGHT h3 27° 35° 38° 30° What if the visual designer decided that fewer users would be interested in the by-hour weather, so those titles should be smaller and not boldWednesday, March 30, 2011
  77. 77. NOTICE ANYTHING ABOUT NESTING & SPECIFICITY? h3 MORN NOON EVENING NIGHT h3 27° 35° 38° 30° #sidebar .weatherMod h3{} #sidebar .weatherMod .hourly h3{}Wednesday, March 30, 2011
  78. 78. NOTICE ANYTHING ABOUT NESTING & SPECIFICITY? h3 MORN NOON EVENING NIGHT h3 27° 35° 38° 30° #sidebar .weatherMod h3{} 0 1 1 1 #sidebar .weatherMod .hourly h3{}Wednesday, March 30, 2011
  79. 79. NOTICE ANYTHING ABOUT NESTING & SPECIFICITY? h3 MORN NOON EVENING NIGHT h3 27° 35° 38° 30° #sidebar .weatherMod h3{} 0 1 1 1 #sidebar .weatherMod .hourly h3{} 0 1 2 1Wednesday, March 30, 2011
  80. 80. SIX MONTHS LATER, IT GETS COMPLICATED ❖ Specificity grows over time ❖ Difficult to tell which rules will take precedence ❖ Developers end up coding by firebugWednesday, March 30, 2011
  81. 81. WHAT HAPPENS WHEN... there are no more ways to make a rule more specific than the one you are trying to override?Wednesday, March 30, 2011
  82. 82. <h3 style=”color: red; font-weight: bold; font-size: 20px;”>My shiny new heading level 3</h3> WHAT HAPPENS WHEN... there are no more ways to make a rule more specific than the one you are trying to override?Wednesday, March 30, 2011
  83. 83. <h3 style=”color: red; font-weight: bold; font-size: 20px;”>My shiny new heading level 3</h3> WHAT HAPPENS WHEN... there are no more ways to make a rule more specific than the one you are trying to override? 1 0 0 0Wednesday, March 30, 2011
  84. 84. AND THEN ANOTHER DEVELOPER SAYS... “this is gross! we should not be using inline-styles” but, at this point, what choice to they have left?Wednesday, March 30, 2011
  85. 85. #sidebar .weatherMod .hourly .tuesday h3{color: blue !important;} YOU MIGHT THINK !IMPORTANT WOULD END the specificity war, not so.Wednesday, March 30, 2011
  86. 86. #sidebar .weatherMod .hourly .tuesday h3{color: blue !important;} YOU MIGHT THINK !IMPORTANT WOULD END the specificity war, not so. 0 0 0 0Wednesday, March 30, 2011
  87. 87. #sidebar .weatherMod .hourly .tuesday h3{color: blue !important;} YOU MIGHT THINK !IMPORTANT WOULD END the specificity war, not so. 0 0 0 0Wednesday, March 30, 2011
  88. 88. #sidebar .weatherMod .hourly .tuesday h3{color: blue !important;} YOU MIGHT THINK !IMPORTANT WOULD END the specificity war, not so. 0 1 3 1 0 0 0 0Wednesday, March 30, 2011
  89. 89. HOSTILE CODE ENVIRONMENT ❖ Two layers develop ❖ Specificity grows over time (more and more rules become important). ❖ Even more difficult to tell which rules will take precedence ❖ Developers always code by firebug ❖ Eventually, it becomes impossible to get the look and feel you want.Wednesday, March 30, 2011
  90. 90. SPECIFICITY AT IT’S WORST normal IDs Classes ElementsWednesday, March 30, 2011
  91. 91. SPECIFICITY AT IT’S WORST inline Inline Styles normal IDs Classes ElementsWednesday, March 30, 2011
  92. 92. SPECIFICITY AT IT’S WORST !important IDs Classes Elements inline Inline Styles normal IDs Classes ElementsWednesday, March 30, 2011
  93. 93. #sidebar A Normal Heading Level 3Wednesday, March 30, 2011
  94. 94. DUPLICATING PROPERTY VALUE PAIRS h1{ margin: 10px 0; color: #333; font-size: 24px; font-weight: bold} h2{ margin: 10px 0; color: #333; font-size: 19px; font-weight: bold} h3{ margin: 5px 0; color: #333; font-size: 17px; font-weight: bold } #sidebar .collaborators h3{ margin: 5px 0; color: #333; font-size: 17px; font-weight: bold } #sidebar h3{color: #797979; font-size: 12px;font-weight: bold; border-bottom: 1px solid #c5c5c5; padding-bottom: 5px;} #sidebar .account h3{color: #555;font-size: 13px;font-weight: bold;background-color: #deeef8;padding: 5px;margin: 10px 0;} #sidebar .weatherMod h3{} #sidebar .weatherMod .hourly h3{} h4{ margin: 5px 0; color: #333; font-size: 15px; font-weight: bold} h5{ margin: 5px 0; color: #111; font-size: 13px; font-weight: bold} h6{ margin: 10px 0; color: #111; font-size: 12px; font-weight: bold}Wednesday, March 30, 2011
  95. 95. THREE PROBLEMS ❖ Duplication of property value pairs ❖ Duplication of elements (h3) ❖ Growing SpecificityWednesday, March 30, 2011
  96. 96. DUPLICATING ELEMENTS h1{} h2{} h3{} #sidebar .collaborators h3{} #sidebar h3{} #sidebar .account h3{} #sidebar .weatherMod h3{} #sidebar .weatherMod .hourly h3{} h4{} h5{} h6{}Wednesday, March 30, 2011
  97. 97. GROWING SPECIFICITY h1{} h2{} h3{} #sidebar .collaborators h3{} #sidebar h3{} #sidebar .account h3{} #sidebar .weatherMod h3{} #sidebar .weatherMod .hourly h3{} h4{} h5{} h6{}Wednesday, March 30, 2011
  98. 98. HOW DO WE SOLVE THESE PROBLEMS? Examine our best practice myths rationally ❖ Add non-semantic elements judiciously ❖ Keep specificity as low as possible ❖ Abstract repeating visual patterns ❖ Use specificity to define your architectureWednesday, March 30, 2011
  99. 99. MEDIA BLOCK EXAMPLEWednesday, March 30, 2011
  100. 100. ALL OF THESE ARE THE SAME OBJECTWednesday, March 30, 2011
  101. 101. WHAT DO WE KNOW? ❖ Can be nested ❖ Optional right button ❖ Must clearfixWednesday, March 30, 2011
  102. 102. WHAT DON’T WE KNOW? ❖ Image width and decoration vary ❖ Right content is unknown ❖ Width unknownWednesday, March 30, 2011
  103. 103. SEPARATE STRUCTURE FROM CHROMEWednesday, March 30, 2011
  104. 104. A FEW LINES OF HTML... <div class="media attribution"> <a href="http://twitter.com/stubbornella" class="img"> <img src="mini.jpg" alt="Stubbornella" /> </a> <div class="bd">@Stubbornella 14 minutes ago</div> </div>Wednesday, March 30, 2011
  105. 105. 4 LINES OF CSS... _Wednesday, March 30, 2011
  106. 106. Wednesday, March 30, 2011
  107. 107. HTML SIZE reduced by 50% by Stefan ParkerWednesday, March 30, 2011
  108. 108. “Due to these efforts, we cut our average CSS bytes per page by 19% (after gzip) and HTML bytes per page by 44% (before gzip).” Jason Sobel http://www.facebook.com/note.php?note_id=307069903919Wednesday, March 30, 2011
  109. 109. Wednesday, March 30, 2011
  110. 110. GREAT DEVELOPERS CAN BUILD AMAZING THINGS if we move worst-best practices out of our wayWednesday, March 30, 2011
  111. 111. LET’S KEEP TALKING... www.stubbornella.org @stubbornella OOCSS Project: http://github.com/stubbornella/oocss/Wednesday, March 30, 2011

×