The Graceful Degradation of CSS3

10,146 views

Published on

Everyone is falling in love with CSS3, and no small wonder. Learn how to use popular CSS3 properties of the future while respecting the browsers of the past.

Published in: Technology
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
10,146
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
70
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide
  • Add screenshot example slide
  • Add screenshot example slide
  • The Graceful Degradation of CSS3

    1. Denise R. Jacobs PapillonEffect Consulting  BBC London November 2010 It’s Business Time: Gettin’ Down With the Graceful Degradation of CSS3
    2. Meet your presenter CSSDetectiveGuide.com & InterActWithWebStandards.com 1969 2010
    3. On CSS3
    4. The love affair with CSS3 continues to grow stronger and more passionate over time http://www.flickr.com/photos/victoriapeckham/2091704802/
    5. What’s not to love? Easier  implementation of  visual effects Effects that  enhance the user  experience http://www.flickr.com/photos/shibanidutta/4115390982/
    6. Past =
    7. Contortions
    8. Present =
    9. Ease
    10. As with many seemingly perfect romances, there are issues… http://www.flickr.com/photos/cybervin/266632074/
    11. Relationship Status: It’s Complicated
    12. Still a working draft +
    13. Uneven browser support +
    14. Does not validate +
    15. Code bloat Ideally: a.polaroid:active { z-index: 999; border-color: #6A6A6A; box-shadow: 15px 15px 20px rgba(0,0, 0, 0.4); transform: rotate(0deg) scale(1.05); } Reality: a.polaroid:active { z-index: 999; border-color: #6A6A6A; -webkit-box-shadow: 15px 15px 20px rgba(0,0, 0, 0.4); -moz-box-shadow: 15px 15px 20px rgba(0,0, 0, 0.4); box-shadow: 15px 15px 20px rgba(0,0, 0, 0.4); -webkit-transform: rotate(0deg) scale(1.05); -moz-transform: rotate(0deg) scale(1.05); transform: rotate(0deg) scale(1.05); }
    16. = Oh My!
    17. Despite our most fervent prayers
    18. Many users are still using older browsers
    19. Either by force
    20. Or by choice
    21. “Do websites need to look exactly the same in every browser?”
    22. While looks aren’t everything
    23. They do shape user perception and experience
    24. Happy end users
    25. Facilitating compatibility
    26. CSS3 Graceful Degradation: The Necessities
    27. So, which is better, Graceful Degradation or Progressive Enhancement?
    28. * Please *
    29. Sites need be usable and look good to as many people as possible. Period.
    30. What’s in a name? “Progressful Degrahancement” (coined by M. Jackson Wilkinson and Jason  Garber) “Graceful Reverse Degradation” (coined by me)
    31. The end result: most important
    32. Tools
    33. CSS3 Specifications The CSS3 Specifications are THE resource  for finding out the exact intended  behavior and use of any given property. http://www.w3.org/standards/techs/ css#w3c_all
    34. Browser Support Charts http://www.findmebyip.com/ litmus
    35. Cross-Browser Testers http://tredosoft.com/Multiple_IE http://crossbrowsertesting.com/(paid) http://browsershots.org/(free)
    36. Techniques
    37. The Goal Code that displays well in all browsers
    38. …However, Many properties are browser‐specific, requiring  vendor prefixes And there is a standard property There are syntax differences between browser‐ specific properties and the standard property All of this causes an increase in the amount of  CSS Older IEs don’t support CSS3 – need either filters  or helper scripts
    39. Getting as close as possible 1. (Re)set the mood 2. Leverage source order 3. Be conditional 4. Use a filter 5. Add tools to the mix 6. Be proactively defensive
    40. (Re)set the Mood A CSS reset insures that you are starting from a  common base point in all browsers. Example: html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre (etc){ margin: 0; padding: 0; border: 0; outline: 0; font-size: 100%; vertical-align: baseline; background: transparent; } 1.
    41. CSS Resets Eric Meyer’s Reset:  http://meyerweb.com/eric/tools/css/reset/ Article on DIY resets by Jason Cranford  Teague: http://bit.ly/1D4jSB
    42. Place default properties first Place browser‐specific properties ahead of  standard properties The standard properties will override the  vendor’s when the standard is established. Leverage Source Order2.
    43. A Proper Stack .gradient { color: #fff;
    44. A Proper Stack .gradient { color: #fff; background: #aaaaaa url(gradient_slice.jpg) 0 0 x-repeat; /*fallback background color & image*/
    45. A Proper Stack .gradient { color: #fff; background: #aaaaaa url(gradient_slice.jpg) 0 0 x-repeat; /*fallback background color & image*/ background-image: -moz-linear-gradient(top, #07407c, #aaaaaa); /* gradient for Mozilla */
    46. A Proper Stack .gradient { color: #fff; background: #aaaaaa url(gradient_slice.jpg) 0 0 x-repeat; /*fallback background color & image*/ background-image: -moz-linear-gradient(top, #07407c, #aaaaaa); /* gradient for Mozilla */ background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #07407c),color-stop(1, #aaaaaa)); /* gradient for the Webkits */
    47. A Proper Stack .gradient { color: #fff; background: #aaaaaa url(gradient_slice.jpg) 0 0 x-repeat; /*fallback background color & image*/ background-image: -moz-linear-gradient(top, #07407c, #aaaaaa); /* gradient for Mozilla */ background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #07407c),color-stop(1, #aaaaaa)); /* gradient for the Webkits */ -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorStr=' #07407c', EndColorStr='#aaaaaa')"; /* filter for IE8 (& IE9) */
    48. A Proper Stack .gradient { color: #fff; background: #aaaaaa url(gradient_slice.jpg) 0 0 x-repeat; /*fallback background color & image*/ background-image: -moz-linear-gradient(top, #07407c, #aaaaaa); /* gradient for Mozilla */ background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #07407c),color-stop(1, #aaaaaa)); /* gradient for the Webkits */ -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorStr=' #07407c', EndColorStr='#aaaaaa')"; /* filter for IE8 (& IE9) */ filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='# 07407c', EndColorStr='#aaaaaa'); } /* filter for IE7 and lower */
    49. Establish Conditions <!--[if gte IE 6]> <link href="ie_stylesheet.css" rel="stylesheet"> <![endif]--> (place after the regular stylesheet link to override  styles) 3.
    50. If you must have the effect in IE, such as  alpha opacity, gradient, shadow, transitions  etc. you could use a proprietary IE filter. {Caveat Coder} IE filters work, but are essentially hacks – IE filters are proprietary and thus not part of  any standard specification, and never will be Apply a Filter4.
    51. Filter extensions The -ms-filter attribute is an  extension to CSS for IE8 and above. This  syntax will allow other CSS parsers to skip  the value of this unknown property  completely and safely. It also avoids future  name clashes with other CSS parsers. 
    52. Filter extension syntax For IE8+, not only must filters be prefixed  with "‐ms‐" , but the PROGID must be in  single or double quotes to make sure the  browsers render the filters properly. Example: -ms-filter: "progid:DXImageTransform.Microsoft.Shad ow(Strength=2, Direction=135, Color='#305052')";
    53. Get Script Help There are several scripts, javascript libraries,  and jquery scripts and plugins that will help  older browsers mimic modern ones. 5.
    54. Ie-7.js http://code.google.com/p/ie7-js/
    55. CSS3Pie.com
    56. CSS Sandpaper http://www.useragentman.com/blog/csssandpaper-a-css3-javascript-library/
    57. Be Proactive Defensive coding for older browsers helps  you to quickly and easily identify and solve  problems when they come up  Organize for easy reading and access Optimize for loading speed Build in bug fixes 6.
    58. The “Special” Relationship: Dealing with the IEs
    59. The older IEs DO NOT support CSS3 …as in “at all.” Right. Enough said. 6 7 8 http://www.flickr.com/photos/johnsnape/4258191545/
    60. 9 Initial reports of IE9 support of CSS3
    61. The reality
    62. Dealing with IE6 (Still? Yes, still.) Approaches: Kick it to the curb Exercise tolerance Full Respect: show grace in degradation
    63. IE6: Go home! http://www.flickr.com/photos/robotjohnny/3629069606/
    64. Having “the talk” In IE6In modern browsers paulcarbo.net
    65. Serve some stripped-down style makephotoshopfaster.com In IE6In modern browsers
    66. Resource: Universal IE CSS Universal IE6 stylesheet: http://code.google.com/p/universal-ie6-css/
    67. Make a helpful suggestion http://yaronschoen.com/blog/sudden_metanoia In IE6In modern browsers
    68. Resource: BrowseSad.org browsesad.org
    69. Limit Your Support gowalla.com
    70. Showing a little extra Love.
    71. Respectful, yet graceful aposd.org In IE6In modern browsers
    72. Let’s Get It On
    73. 8 CSS3 Properties with Graceful Degradation Fallbacks
    74. The Properties 1. @font‐face 2. border‐radius 3. opacity 4. rgba 5. box‐shadow 6. text‐shadow 7. gradient 8. transform
    75. Warning: this may put you in the mood for some serious…coding
    76. @font-face1.
    77. http://sickdesigner.com/ @font-face1.
    78. @font-face Note: – Actually part of the CSS2.1 specification.  – Therefore, the IEs do support it! Browser Support – The older IEs require fonts to be in EOT format – IE9 now supports WOFF (web open font face)
    79. @font-face Tips & issues – Potential font license restrictions – Flash of unstyled text (“fout”) Graceful degradation – Desired font should display in all browsers. If not,  fallback fonts will display – Extra credit: image replacement through  conditional comments
    80. @font-face bug: the IEs @font-face super bullet‐proofing The problem: @font‐face doesn’t work, even with the proper  normal syntax. What gives? The solution: Separate out the .eot call with a new @font‐face  declaration.
    81. @font-face bug: Webkit @font-face bold and italics “bug” The problem: Applying font-weight:bold or font-style: italic to @font‐face'd text doesn’t work. The solution: Add the value normal to font weight, style, and  variant in the @font‐face declaration to set a baseline.
    82. Full solution: @font-face @font-face { font-family: 'Colaborate Light'; src: url('ColabLig.eot'); } @font-face { font-family: 'Colaborate Light'; src: local('☺'), url('ColabLig.woff') format('woff'), url('ColabLig.ttf') format('truetype'); font-weight:normal; font-style:normal; font-variant:normal; }
    83. Full solution: @font-face @font-face { font-family: 'Colaborate Light'; src: url('ColabLig.eot'); } @font-face { font-family: 'Colaborate Light'; src: local('☺'), url('ColabLig.woff') format('woff'), url('ColabLig.ttf') format('truetype'); font-weight:normal; font-style:normal; font-variant:normal; }
    84. In modern browsers In IE 8 with fallback font Graceful degradation: @font-face
    85. FontSquirrel.com http://www.fontsquirrel.com/fontface
    86. border-radius2.
    87. border-radius2. http://www.denisejacobs.com/cdgexamples/chapter10/
    88. border-radius Tips & issues – Different syntax for mozilla, webkit, and opera  browsers Graceful Degradation – Square corners are okay – Extra credit: serve images through conditional  comments
    89. border-radius Syntax comparison breakdown: ‐moz allows multiple values for each position ‐webkit individual values Standard is like mozilla
    90. border-radius syntax
    91. Full solution: border-radius #contentcolumn { margin: -40px 3% 0 3%; width: 42%; -moz-border-radius: 20px 20px 0 0; -webkit-border-top-left-radius: 20px; -webkit-border-top-right-radius: 20px; border-radius: 20px 20px 0 0; }
    92. In modern browsers In IE 7, image replacement through conditional comments Graceful Degradation: border-radius
    93. Full solution: border-radius Conditional Comment: <!--[if gte IE 6]> <link rel="stylesheet" type="text/css" href="ohhai_ie78.css" /> <![endif]--> IE7/8 CSS #contentcolumn { background: url(bg_content_left.png) top left no-repeat; display: inline; margin: -40px 3% 0 3%; padding: 0 0 0 0; width: 41.9%; } #content { background: url(bg_content_right.png) top right no-repeat; margin: 7px auto 0 26px; padding: 0 0 50px 0; }
    94. In modern browsers In IE 6, no image replacement Graceful Degradation: border-radius
    95. opacity3.
    96. opacity3. http://rustinjessen.com/weblog/833
    97. opacity Tips & issues – Do not use on elements that would cover  important content Graceful Degradation – Accept that effect will not work in non‐supportive  browsers – Could use a IE filter if absolutely necessary.
    98. Full solution: opacity .opacity { color: #fff; background-color: #3C4C55; opacity: 0.2; -ms-filter: "progid:DXImageTransform.Microsoft.Alpha (opacity=20)"; /* IE8 only */ filter: progid:DXImageTransform.Microsoft.Alpha (opacity=20); /* IE6, IE7, and IE8 */ filter: alpha(opacity=20); }
    99. In modern browsers In IE7, no opacity Graceful degradation: opacity
    100. rgba4.
    101. rgba4. http://aarronwalter.com/designer/
    102. rgba Tips & issues – More granular control of particular elements than opacity – Place after regular rgb color property to override in  modern browsers; older browsers will ignore it – IE bug: use the property background instead of  background-color for the regular color Graceful Degradation – There is an IE filter that gives transparency with a color – Use a png for fallback if desired
    103. Full solution: rgba .rgba { background-color: #ff0000; /* fallback color in hexidecimal */ background-color: transparent; /* transparent is key for the filter to work in IE8. best done through conditional comments */ background-color: rgba(255, 0, 0, 0.3); /* rgba value for modern browsers */ -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorst r=#4CFF0000, endColorstr=#4CFF0000)"; /* filter for IE8 */ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr =#4CFF0000, endColorstr=#4CFF0000); /* filter for older IEs */ }
    104. In modern browsers In IE 7, no rgba Graceful degradation: rgba
    105. box-shadow5.
    106. box-shadow5. http://badassideas.com/work/
    107. box-shadow Tips & issues – Okay if users don’t see effect, doesn’t affect  usability of the page. Graceful Degradation – There is a filter for IE: shadow (actually there are  2: dropshadow as well, but shadow is said to be  better) – Extra credit: serve images through conditional  comments if you don’t want to use the filter.
    108. box-shadow syntax Syntax breakdown: box-shadow: <x-offset> <y-offset> <blur> <color>
    109. Full solution: box-shadow .boxshadow { -moz-box-shadow: 3px 3px 10px #333; -webkit-box-shadow: 3px 3px 10px #333; box-shadow: 3px 3px 10px #333; /*standard*/ -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength =4, Direction=135, Color='#333333')"; /* For IE 8 */ filter: progid:DXImageTransform.Microsoft.Shadow(Strength= 4, Direction=135, Color='#333333'); /* For IE 5.5 - 7 */ }
    110. In modern browsers In IE 7, sans box shadow Graceful degradation: box-shadow
    111. text-shadow6.
    112. text-shadow6. http://www.bountybev.com/home.html
    113. text-shadow Tips & issues – Can help accentuate text and improve readability  and visual importance Graceful Degradation – If it doesn’t show up, that’s okay ‐‐ no impact on  accessibility – There is an IE filter: shadow. – Extra credit: image replacement
    114. Full solution: text-shadow .textshadow h2 { text-shadow: 1px 1px 2px rgba(48,80,82,0.8); -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength =2, Direction=135, Color='#305052')"; /* For IE 8/9 */ filter: progid:DXImageTransform.Microsoft.Shadow(Strength= 2, Direction=135, Color='#305052'); } /* For IE 5.5 - 7 */
    115. In modern browsers In IE 7 without text shadow Graceful degradation: text-shadow
    116. gradient7.
    117. gradient7. http://www.denisejacobs.com/cdgexamples/chapter8/
    118. gradient Tips & issues – Different syntax for mozilla and webkit browsers Graceful Degradation – Gradient will not appear older browsers: IE and  Opera do not support, so will still need a fallback  image* * which may make you wonder: “then why use it at all?” – Establish fallback background image first in code
    119. gradient syntax
    120. #mainnav li a { background-color: #f7f6f4; background-image: url(bg_navitems.gif); background-image: -moz-linear-gradient(100% 100% 90deg, #ccc9ba, #ffffff); background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#ffffff), to(#ccc9ba)); } gradient syntax
    121. Full solution: gradient .gradient { color: #fff; background: #aaaaaa url(gradient_slice.jpg) 0 0 x-repeat; /*background color matches one of the stop colors. The gradient_slice.jpg is 1px wide */ background-image: -moz-linear-gradient(top, #07407c, #aaaaaa); background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, #07407c),color-stop(1, #aaaaaa)); -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorStr=' #07407c', EndColorStr='#aaaaaa')"; /* IE8+ */ filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='# 07407c', EndColorStr='#aaaaaa'); /* IE7- */ }
    122. Graceful degradation: gradient In modern browsers In IE, with fallback image & conditional  comment for rounded corners
    123. Colorzilla gradient tool http://www.colorzilla.com/gradient-editor/
    124. transform8.
    125. transform (2d)8. http://www.zurb.com/playground/css3-polaroids/
    126. transform Tips & issues – Mozilla, webkit, and opera vendor prefixes, but no  standard yet. – Rendering uneven: jagged edges in the Webkits Graceful Degradation – Leave images/elements in standard orientation or  shape – There is an IE filter: matrix. – Extra credit: serve images or image sprites with  conditional comments
    127. transform: types • rotate • scale • skew • translate • matrix
    128. transform: rotate syntax The generic syntax for transform is <-prefix->transform: type(<value>) type(<value>) type(<value>) type(<value>); For rotate specifically, here is the syntax: <-prefix->transform: rotate(<value>) Positive values will rotate the object clockwise to the right, and  negative values will rotate the element counter‐clockwise to  the left.
    129. #photos img { -webkit-transform: rotate(-2deg); -moz-transform: rotate(-2deg); -o-transform: rotate(-2deg); } transform: rotate
    130. In modern browsers In IE 7 without transform Graceful degradation: transform
    131. Useful Tools
    132. More tools to do the heavy lifting
    133. CSS3 Generators
    134. CSS3Please.com
    135. CSS3Generator.com
    136. CSS3-Maker.com
    137. CSS3 Tools at WestCiv http://westciv.com/tools/
    138. Even more CSS3 Generators http://csscorners.com/ http://border‐image.com
    139. Helper Scripts
    140. Modernizr.com
    141. Templates
    142. HTML5Boilerplate.com Paul Irish’s HTML5 template file http://html5boilerplate.com/
    143. Final Thoughts
    144. “Can I use CSS3 now?”
    145. Make the…
    146. Try out some new moves
    147. Totally hot
    148. Coding superhero
    149. Resources delicious.com/denisejacobs/ gdcss3 delicious.com/denisejacobs/ gdcss3examples delicious.com/denisejacobs/css3
    150. Thank you! denisejacobs.com denise@denisejacobs.com twitter.com/denisejacobs slideshare.net/denisejacobs
    151. Closed.

    ×