{"id":62,"date":"2011-01-18T11:27:24","date_gmt":"2011-01-18T17:27:24","guid":{"rendered":"http:\/\/timothypoon.com\/blog\/?p=62"},"modified":"2011-01-19T09:53:11","modified_gmt":"2011-01-19T15:53:11","slug":"css3-trickery-a-lesson-in-gradients-and-masks","status":"publish","type":"post","link":"https:\/\/timothypoon.com\/blog\/2011\/01\/18\/css3-trickery-a-lesson-in-gradients-and-masks\/","title":{"rendered":"CSS3 Trickery: A Lesson in Gradients and Masks"},"content":{"rendered":"<p>I&#8217;m currently working on a project where one of the designs I&#8217;m to implement involves making one of these suckers:<\/p>\n<p><a href=\"http:\/\/timothypoon.com\/blog\/wp-content\/uploads\/2011\/01\/css3-trickery-1.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-63\" title=\"Grayed out steps\" src=\"http:\/\/timothypoon.com\/blog\/wp-content\/uploads\/2011\/01\/css3-trickery-1.png\" alt=\"\" width=\"100%\" srcset=\"https:\/\/timothypoon.com\/blog\/wp-content\/uploads\/2011\/01\/css3-trickery-1.png 990w, https:\/\/timothypoon.com\/blog\/wp-content\/uploads\/2011\/01\/css3-trickery-1-300x22.png 300w\" sizes=\"(max-width: 990px) 100vw, 990px\" \/><\/a><\/p>\n<p>However, that&#8217;s not all. Based on where the user is amidst these four steps, it will actually end up looking something like this:<\/p>\n<p><a href=\"http:\/\/timothypoon.com\/blog\/wp-content\/uploads\/2011\/01\/css3-trickery-2.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-64\" title=\"Partially completed steps\" src=\"http:\/\/timothypoon.com\/blog\/wp-content\/uploads\/2011\/01\/css3-trickery-2.png\" alt=\"\" width=\"100%\" srcset=\"https:\/\/timothypoon.com\/blog\/wp-content\/uploads\/2011\/01\/css3-trickery-2.png 990w, https:\/\/timothypoon.com\/blog\/wp-content\/uploads\/2011\/01\/css3-trickery-2-300x22.png 300w\" sizes=\"(max-width: 990px) 100vw, 990px\" \/><\/a><\/p>\n<p>Normally, I&#8217;d achieve this with <a href=\"http:\/\/css-tricks.com\/css-sprites\/\" title=\"CSS Sprites: What They Are, Why They're Cool, and How To Use Them | CSS-Tricks\">CSS sprites<\/a> and be rather sad about it all since whatever I&#8217;d be doing would be either a) not semantically correct, or b) terribly convoluted. Luckily, this project is specified to only having to run on Chrome, which I finally get to use some <a href=\"http:\/\/www.w3.org\/TR\/css3-roadmap\/\" title=\"Introduction to CSS3\">CSS3<\/a> and not care who knows it.<\/p>\n<h2>The First Attempt<\/h2>\n<p>Let&#8217;s back up a bit, though. Before the designer got his hands on this project, I was actually both designing and developing the entire shebang, so I actually had the entire thing already coded out, HTML, CSS, Javascript, PHP, and all. However, the company I work for finally got around to hiring a real designer, so out went my intuitive and <a href=\"http:\/\/developer.apple.com\/library\/ios\/#documentation\/UserExperience\/Conceptual\/MobileHIG\/Introduction\/Introduction.html\" title=\"iOS Human Interface Guidelines: Introduction\">standards<\/a>&#8211;<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/cc872774.aspx\" title=\"Touch\">compliant<\/a> touch interface and in came a guy with a graphic design degree who thought 18px was tall enough for buttons in a touch UI.<\/p>\n<p>Anyways, here was my original markup for these steps:<\/p>\n<div class=\"codecolorer-container html4strict railscasts\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/><\/div><\/td><td><div class=\"html4strict codecolorer\"><span class=\"sc2\">&lt;<a href=\"http:\/\/december.com\/html\/4\/element\/ul.html\"><span class=\"kw2\">ul<\/span><\/a> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;steps&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<a href=\"http:\/\/december.com\/html\/4\/element\/li.html\"><span class=\"kw2\">li<\/span><\/a> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;done&quot;<\/span>&gt;<\/span>1. Prescription<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><a href=\"http:\/\/december.com\/html\/4\/element\/li.html\"><span class=\"kw2\">li<\/span><\/a>&gt;<\/span> <br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<a href=\"http:\/\/december.com\/html\/4\/element\/li.html\"><span class=\"kw2\">li<\/span><\/a>&gt;<\/span>2. Lenses<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><a href=\"http:\/\/december.com\/html\/4\/element\/li.html\"><span class=\"kw2\">li<\/span><\/a>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<a href=\"http:\/\/december.com\/html\/4\/element\/li.html\"><span class=\"kw2\">li<\/span><\/a>&gt;<\/span>3. Coatings<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><a href=\"http:\/\/december.com\/html\/4\/element\/li.html\"><span class=\"kw2\">li<\/span><\/a>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<a href=\"http:\/\/december.com\/html\/4\/element\/li.html\"><span class=\"kw2\">li<\/span><\/a>&gt;<\/span>4. Checkout<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><a href=\"http:\/\/december.com\/html\/4\/element\/li.html\"><span class=\"kw2\">li<\/span><\/a>&gt;<\/span><br \/>\n<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><a href=\"http:\/\/december.com\/html\/4\/element\/ul.html\"><span class=\"kw2\">ul<\/span><\/a>&gt;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Simple enough, right? In fact, if those black lines weren&#8217;t diagonal, this whole problem could be solved with some border-right and <a href=\"http:\/\/www.w3.org\/TR\/css3-selectors\/#last-child-pseudo\" title=\"Selectors Level 3\">:last-child<\/a> action in addition to the <a href=\"http:\/\/dev.opera.com\/articles\/view\/beautiful-ui-styling-with-css3-text-shadow-box-shadow-and-border-radius\/\" title=\"Beautiful UI styling with CSS3 text-shadow, box-shadow, and border-radius - Dev.Opera\">box-shadow and border-radius<\/a> styles I already had in place. Unfortunately, they&#8217;re about 30&deg; from being easy, so I had to think of something else.<\/p>\n<p>Starting out, I thought I would just apply both the gray and red <a href=\"http:\/\/webkit.org\/blog\/175\/introducing-css-gradients\/\" title=\"Surfin' Safari - Blog Archive  | Introducing CSS Gradients\">gradients<\/a> directly to the &lt;li&gt; elements and use <a href=\"http:\/\/webkit.org\/blog\/130\/css-transforms\/\" title=\"Surfin'; Safari - Blog Archive  |; CSS Transforms\">-webkit-transform<\/a> to rotate() a 1px wide pseudo element. Well, bad idea. That line of thinking ran me into a predicament that looked a bit like this:<\/p>\n<p><a href=\"http:\/\/timothypoon.com\/blog\/wp-content\/uploads\/2011\/01\/css3-trickery-3.png\"><img decoding=\"async\" src=\"http:\/\/timothypoon.com\/blog\/wp-content\/uploads\/2011\/01\/css3-trickery-3.png\" alt=\"\" title=\"Obstacle #1\" width=\"100%\" class=\"aligncenter size-full wp-image-65\" srcset=\"https:\/\/timothypoon.com\/blog\/wp-content\/uploads\/2011\/01\/css3-trickery-3.png 990w, https:\/\/timothypoon.com\/blog\/wp-content\/uploads\/2011\/01\/css3-trickery-3-300x22.png 300w\" sizes=\"(max-width: 990px) 100vw, 990px\" \/><\/a><\/p>\n<p>You&#8217;ll notice that line is aliased to an unacceptable degree, not to mention the fact that having red and gray states next to each other created competing borders that I couldn&#8217;t think of a way to elegantly mask, so I had to change up tactics.<\/p>\n<h2>Progress!<\/h2>\n<p>My first step was to keep the gray gradient wholly contained to the actual &lt;ul&gt; element rather than each individual &lt;li&gt; but keep those pumping out the red gradients. This would help avoid the issue I had with my original solution where two borders at equal z-indexes were vying for dominance.<\/p>\n<p>Then, I inserted a <a href=\"http:\/\/www.w3.org\/TR\/css3-selectors\/#gen-content\" title=\"Selectors Level 3\">pseudo element<\/a> that simply rendered a diagonal gradient that went from transparent to (almost) black to transparent with some slight fading for aesthetic appeal.<\/p>\n<div class=\"codecolorer-container css railscasts\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/><\/div><\/td><td><div class=\"css codecolorer\">#<span class=\"kw3\">steps<\/span> li<span class=\"sy0\">:<\/span><span class=\"kw5\">before<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">content<\/span><span class=\"sy0\">:<\/span><span class=\"st0\">''<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">display<\/span><span class=\"sy0\">:<\/span><span class=\"kw2\">block<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">position<\/span><span class=\"sy0\">:<\/span><span class=\"kw2\">absolute<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">width<\/span><span class=\"sy0\">:<\/span><span class=\"re3\">40px<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">height<\/span><span class=\"sy0\">:<\/span><span class=\"re3\">54px<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">top<\/span><span class=\"sy0\">:<\/span><span class=\"nu0\">0<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">left<\/span><span class=\"sy0\">:<\/span><span class=\"re3\">-20px<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">background<\/span><span class=\"sy0\">:<\/span>-webkit-gradient<span class=\"br0\">&#40;<\/span>linear<span class=\"sy0\">,<\/span> <span class=\"kw2\">left<\/span> <span class=\"nu0\">14<\/span><span class=\"sy0\">,<\/span> <span class=\"kw2\">right<\/span> <span class=\"nu0\">40<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">0%<\/span><span class=\"sy0\">,<\/span> <span class=\"kw4\">transparent<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">48%<\/span><span class=\"sy0\">,<\/span> <span class=\"kw4\">transparent<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">50%<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">#676767<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">50%<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">#676767<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">52%<\/span><span class=\"sy0\">,<\/span> <span class=\"kw4\">transparent<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">100%<\/span><span class=\"sy0\">,<\/span> <span class=\"kw4\">transparent<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>If you can&#8217;t tell, this is the diagonal line. It&#8217;s not as straightforward or as neat as using -webkit-transform, but it renders way better on the screen.<\/p>\n<p>However, this still didn&#8217;t solve the issue of mixing diagonal lines with vertical gradients. No, that had to be rectified with another pseudo element.<\/p>\n<div class=\"codecolorer-container css railscasts\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/><\/div><\/td><td><div class=\"css codecolorer\">#<span class=\"kw3\">steps<\/span> li<span class=\"re1\">.done<\/span><span class=\"sy0\">:<\/span><span class=\"kw5\">before<\/span><span class=\"sy0\">,<\/span> #<span class=\"kw3\">steps<\/span> li<span class=\"re1\">.done<\/span> <span class=\"sy0\">+<\/span> li<span class=\"sy0\">:<\/span><span class=\"kw5\">not<\/span><span class=\"br0\">&#40;<\/span>.done<span class=\"br0\">&#41;<\/span><span class=\"sy0\">:<\/span><span class=\"kw5\">before<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">background<\/span><span class=\"sy0\">:<\/span><br \/>\n&nbsp; &nbsp; -webkit-gradient<span class=\"br0\">&#40;<\/span>linear<span class=\"sy0\">,<\/span> <span class=\"kw2\">left<\/span> <span class=\"nu0\">14<\/span><span class=\"sy0\">,<\/span> <span class=\"kw2\">right<\/span> <span class=\"nu0\">40<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">0%<\/span><span class=\"sy0\">,<\/span> <span class=\"kw4\">transparent<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">48%<\/span><span class=\"sy0\">,<\/span> <span class=\"kw4\">transparent<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">50%<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">#592327<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">50%<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">#592327<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">52%<\/span><span class=\"sy0\">,<\/span> <span class=\"kw4\">transparent<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">100%<\/span><span class=\"sy0\">,<\/span> <span class=\"kw4\">transparent<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; -webkit-gradient<span class=\"br0\">&#40;<\/span>linear<span class=\"sy0\">,<\/span> <span class=\"kw2\">left<\/span> <span class=\"kw2\">top<\/span><span class=\"sy0\">,<\/span> <span class=\"kw2\">left<\/span> <span class=\"kw2\">bottom<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">0%<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">#CA263D<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">100%<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">#850304<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n#<span class=\"kw3\">steps<\/span> li<span class=\"re1\">.done<\/span> <span class=\"sy0\">+<\/span> li<span class=\"sy0\">:<\/span><span class=\"kw5\">not<\/span><span class=\"br0\">&#40;<\/span>.done<span class=\"br0\">&#41;<\/span><span class=\"sy0\">:<\/span><span class=\"kw5\">not<\/span><span class=\"br0\">&#40;<\/span>.current<span class=\"br0\">&#41;<\/span><span class=\"sy0\">:<\/span><span class=\"kw5\">after<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">content<\/span><span class=\"sy0\">:<\/span><span class=\"st0\">''<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">display<\/span><span class=\"sy0\">:<\/span><span class=\"kw2\">block<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">position<\/span><span class=\"sy0\">:<\/span><span class=\"kw2\">absolute<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">width<\/span><span class=\"sy0\">:<\/span><span class=\"re3\">40px<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">height<\/span><span class=\"sy0\">:<\/span><span class=\"re3\">54px<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">top<\/span><span class=\"sy0\">:<\/span><span class=\"nu0\">0<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">left<\/span><span class=\"sy0\">:<\/span><span class=\"re3\">-20px<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">background<\/span><span class=\"sy0\">:<\/span><br \/>\n&nbsp; &nbsp; -webkit-gradient<span class=\"br0\">&#40;<\/span>linear<span class=\"sy0\">,<\/span> <span class=\"kw2\">left<\/span> <span class=\"nu0\">14<\/span><span class=\"sy0\">,<\/span> <span class=\"kw2\">right<\/span> <span class=\"nu0\">40<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">0%<\/span><span class=\"sy0\">,<\/span> <span class=\"kw4\">transparent<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">48%<\/span><span class=\"sy0\">,<\/span> <span class=\"kw4\">transparent<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">50%<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">#592327<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">50%<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">#592327<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">52%<\/span><span class=\"sy0\">,<\/span> <span class=\"kw4\">transparent<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">100%<\/span><span class=\"sy0\">,<\/span> <span class=\"kw4\">transparent<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; -webkit-gradient<span class=\"br0\">&#40;<\/span>linear<span class=\"sy0\">,<\/span> <span class=\"kw2\">left<\/span> <span class=\"kw2\">top<\/span><span class=\"sy0\">,<\/span> <span class=\"kw2\">left<\/span> <span class=\"kw2\">bottom<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">0%<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">#E2E2E2<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">100%<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">#949494<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; -webkit-mask-box-image<span class=\"sy0\">:<\/span>-webkit-gradient<span class=\"br0\">&#40;<\/span>linear<span class=\"sy0\">,<\/span> <span class=\"kw2\">left<\/span> <span class=\"nu0\">14<\/span><span class=\"sy0\">,<\/span> <span class=\"kw2\">right<\/span> <span class=\"nu0\">40<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">0%<\/span><span class=\"sy0\">,<\/span> <span class=\"kw4\">transparent<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">51%<\/span><span class=\"sy0\">,<\/span> <span class=\"kw4\">transparent<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">51%<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">#000000<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span> color-stop<span class=\"br0\">&#40;<\/span><span class=\"re3\">100%<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">#000000<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>While admittedly this isn&#8217;t the most beautiful piece of code I&#8217;ve ever come up with, it does work and works well. The :before changes for .done states by using two gradients for its <a href=\"http:\/\/www.css3.info\/preview\/multiple-backgrounds\/\" title=\"Multiple backgrounds with CSS3 - CSS3 . Info\">multiple backgrounds<\/a>: one diagonal for the line and one vertically for the red background. This leaves a red unwanted triangle on neighboring red\/gray steps, so the :after element recreates the gray gradient and applies a diagonal <a href=\"http:\/\/webkit.org\/blog\/181\/css-masks\/\" title=\"Surfin' Safari - Blog Archive  | CSS Masks\">mask<\/a> to the top left portion of it.<\/p>\n<p><a href=\"http:\/\/timothypoon.com\/blog\/wp-content\/uploads\/2011\/01\/css3-trickery-4.png\"><img decoding=\"async\" src=\"http:\/\/timothypoon.com\/blog\/wp-content\/uploads\/2011\/01\/css3-trickery-4.png\" alt=\"\" title=\"Final product\" width=\"100%\" class=\"aligncenter size-full wp-image-66\" srcset=\"https:\/\/timothypoon.com\/blog\/wp-content\/uploads\/2011\/01\/css3-trickery-4.png 990w, https:\/\/timothypoon.com\/blog\/wp-content\/uploads\/2011\/01\/css3-trickery-4-300x22.png 300w\" sizes=\"(max-width: 990px) 100vw, 990px\" \/><\/a><\/p>\n<p>Booya.<\/p>\n<p><a href=\"\/blog\/demos\/css-trickery\/\" title=\"CSS3 Trickery: A Lesson in Gradients and Masks Demo\">View the demo<\/a> (requires you to be running a <a href=\"http:\/\/webkit.org\/\" title=\"The WebKit Open Source Project\">WebKit browser<\/a>).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m currently working on a project where one of the designs I&#8217;m to implement involves making one of these suckers: However, that&#8217;s not all. Based on where the user is amidst these four steps, it will actually end up looking something like this: Normally, I&#8217;d achieve this with CSS sprites and be rather sad about it all since whatever I&#8217;d be doing would be either a) not semantically correct, or b) terribly convoluted. Luckily, this project is specified to only having to run on Chrome, which I finally get to&#8230;<a class=\"read-more\" href=\"https:\/\/timothypoon.com\/blog\/2011\/01\/18\/css3-trickery-a-lesson-in-gradients-and-masks\/\">read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1,4],"tags":[13,14,15],"class_list":["post-62","post","type-post","status-publish","format-standard","hentry","category-code","category-design","tag-css","tag-css3","tag-html","et-no-image","et-bg-layout-dark","et-white-bg"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p462yg-10","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/timothypoon.com\/blog\/wp-json\/wp\/v2\/posts\/62","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/timothypoon.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/timothypoon.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/timothypoon.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/timothypoon.com\/blog\/wp-json\/wp\/v2\/comments?post=62"}],"version-history":[{"count":0,"href":"https:\/\/timothypoon.com\/blog\/wp-json\/wp\/v2\/posts\/62\/revisions"}],"wp:attachment":[{"href":"https:\/\/timothypoon.com\/blog\/wp-json\/wp\/v2\/media?parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/timothypoon.com\/blog\/wp-json\/wp\/v2\/categories?post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/timothypoon.com\/blog\/wp-json\/wp\/v2\/tags?post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}