<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>User Agent Man</title>
	<atom:link href="http://www.useragentman.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.useragentman.com/blog</link>
	<description>A Blog about Client Side Web Technology</description>
	<lastBuildDate>Thu, 26 Jan 2012 03:14:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Help Free Saeed Malekpour: Sentenced To Death For Writing Code.</title>
		<link>http://www.useragentman.com/blog/2012/01/23/help-free-saeed-malekpour-sentenced-to-death-for-writing-code/</link>
		<comments>http://www.useragentman.com/blog/2012/01/23/help-free-saeed-malekpour-sentenced-to-death-for-writing-code/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 05:02:26 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=4416</guid>
		<description><![CDATA[<img src="http://www.useragentman.com/blog/wp-content/uploads/2012/01/saeed.jpg" /> Imagine you create software for a client.  You do a good job, you are proud of your work, and you put your name and contact info in the heading of the code's comments.  I've done it many times with both code that I have been paid for as well as stuff I open-source and share with the community.  If you are a web developer (or any type of developer for that matter) you probably have done the same thing.  Who would have thought you could be sentenced to death for it?  Please read this article and find out how you can help a web developer who is in this unfortunate situation.]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignleft" style="width: 430px">
<iframe width="420" height="315" src="http://www.youtube.com/embed/sZPot5auoLA?cc_load_policy=1" frameborder="0" allowfullscreen></iframe><br />
<small>Saeed Malekpour&#8217;s wife, Fatima Eftekhari, discussing the current situation.</small>
</div>
<p> <strong><em>If you are a web developer, or any kind of code wrangler, please take a minute out of your day to read what follows.  I don&#8217;t usually write article of a political nature, but as a web developer this really hits close to home and I would never want this to happen to me.</em></strong></p>
<p>Imagine you create software for a client.  You do a good job, you are proud of your work, and you put your name and contact info in the heading of the code&#8217;s comments.  I&#8217;ve done it many times with both code that I have been paid for as well as stuff I open-source and share with the community.  If you are a web developer (or any type of developer for that matter) you probably have done the same thing.  Who would have thought you could be sentenced to death for it?</p>
<p>This is the story of a man named <a href="https://peoplewithoutnation.wordpress.com/">Saeed Malekpour</a>, a man from Iran who lived in Canada until recently.  He apparently created software that can be used to upload photos to a website.  When he went back to Iran in 2008 to visit his sick father, he was arrested because that software he created was used on a pornographic website.  The Iranian government also accused Saeed with <a href="http://www.thestar.com/news/world/article/1117318--canadian-resident-faces-execution-in-iran-after-appeal-is-rejected">designing pornographic websites and &#8220;insulting Islam&#8221;</a> (the government tortured him and extract a forced confession of these crimes, according to <a href="http://peoplewithoutnation.wordpress.com/saeed-malekpour-open-letter-to-the-iri-judiciary/">a letter Saeed wrote in prison</a>).  This week, Saeed was sentenced to death.  <strong>Even if these accusations were true (which I don&#8217;t think they are), why on Earth would that be considered a capital crime?</strong></p>
<p>I look at his situation, and I think of all the software I have ever written and released on to clients or open sourced on this blog.  After I release the software, I have no say on what people do with it.  I look at Saeed&#8217;s situation, and think that if <strong>I was Iranian, this could be me.</strong>  If you are a computer programmer of any description, <strong>imagine this being you.</strong></p>
<p>Saeed doesn&#8217;t have a lot of time, so <strong>I ask anyone who reads my blog, especially those in the web development community, <a href="http://peoplewithoutnation.wordpress.com/letter/">please help this cause by visiting this page</a> or filling out <a href="http://org2.democracyinaction.org/o/6160/p/dia/action/public/?action_KEY=4581">this online petition to Canadian Prime Minister Stephen Harper</a>.</strong>  You can also publicize the official <a href="http://peoplewithoutnation.wordpress.com/">Campaign for Release of Saeed Malekpour</a> to whatever social network(s) you belong to.  Doing so may raise awareness on this issue and hopefully help Saeed off of death row and back home where he belongs. </p>
<h2>Further Reading</h2>
<ul>
<li><a href="http://www.cbc.ca/video/player.html?clipid=1811391663&#038;position=246210&#038;site=cbc.news.ca">Iran Executions: Saeed Malekpour</a> with an radio interview of Saeed Malekpour&#8217;s wife Fatima on CBC&#8217;s <a href="http://www.cbc.ca/thecurrent/">The Current</a></li>
<li><a href="http://www.thestar.com/news/world/article/1120155--protests-spread-as-gta-man-faces-execution-in-iran">Protests spread as GTA man faces execution in Iran</a> &#8211; by <a href="http://www.thestar.com/unassigned/columnists/94633--ward-olivia">Olivia Ward</a>, <a href="http://www.thestar.com">Toronto Star</a>.</li>
<li><a href="http://www.cbc.ca/news/canada/toronto/story/2012/01/18/toronto-iran-death-sentence.html">Toronto-area man faces death in Iran prison</a>, from <a href="http://www.cbc.ca/">CBC News</a></li>
<li><a href="http://www.guardian.co.uk/world/2012/jan/18/iran-death-sentence-porn-programmer?newsfeed=true">Iran confirms death sentence for &#8216;porn site&#8217; web programmer</a> by <a class="contributor" rel="author" href="http://www.guardian.co.uk/profile/saeedkamalidehghan">Saeed Kamali Dehghan</a>, <a href="http://www.guardian.co.uk">The Guardian</a></li>
<li><a href="http://yro.slashdot.org/story/12/01/22/0354253/web-developer-sentenced-to-death-in-iran">Web Developer Sentenced To Death In Iran</a> posted on <a href="http://slashdot.org/">Slashdot</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2012/01/23/help-free-saeed-malekpour-sentenced-to-death-for-writing-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Caching Images With JavaScript and HTML5 progress Bars</title>
		<link>http://www.useragentman.com/blog/2012/01/16/caching-images-with-javascript-and-html5-progress-bars/</link>
		<comments>http://www.useragentman.com/blog/2012/01/16/caching-images-with-javascript-and-html5-progress-bars/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 02:03:30 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=4329</guid>
		<description><![CDATA[<img src="/blog/wp-content/uploads/2012/01/loading.jpg" />HTML5 Progress Bars are cool, <strong>but where would you use one?</strong>  If you are have a page with a lot of images that are being animated, you may not want to the content to be visible until is all loaded into memory, so why not use a progress bar to show the load progression? This article will show how to <strong>make a simple slideshow with a progress bar</strong> that updates as images are loaded.  Proof that HTML5 progress bars are useful and not just a bunch of eye-candy with a fancy name.]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_4354" class="wp-caption alignleft" style="width: 260px"><a href="http://www.useragentman.com/examples/progress/dnfmomd.html"><img src="http://www.useragentman.com/blog/wp-content/uploads/2012/01/loading.jpg" alt="" title="loading" width="250" height="180" class="size-full wp-image-4354" /></a><p class="wp-caption-text">Progress Bars can be used to show users how long it will be until a high-traffic page, like a photo gallery, fully loads.  Click on the image to see one in action. (Photos courtesy of Do Not Forsake Me Oh My Darling)</p></div> <strong>In my last article</strong>, <em><a href="http://www.useragentman.com/blog/2012/01/03/cross-browser-html5-progress-bars-in-depth/" rel="prev">Cross Browser HTML5 Progress Bars In Depth</a></em>, <strong>I discussed how to create progress bars</strong> and how to do fancy-pants CSS styling on them in all browsers.  Sure, it&#8217;s cool eye candy, <strong>but where would you use one?</strong>  I&#8217;m sure you have seen <strong>Flash sites that have a progress bars</strong> before (or what some of my designer friends call a &#8220;loader&#8221;), but just in case, <strong>take a look at the <a href="http://www.startrekmovie.com/">Star Trek Movie site</a> to see an example of one in the wild.</strong>  This loader tells the user how long it will take for the page to load and display. If this page takes a long time to load, <strong>a loader will prevent users from thinking the page is not loading properly</strong> and go someplace else. In most cases, these loaders show the percentage of assets have been loaded, and when it reaches 100%, the content is displayed.  This prevents images from appearing half loaded when the content is first shown.  While I wouldn&#8217;t want loaders for most HTML-based web sites, there are definitely times you would to want to do this, like when creating a full-screen slideshow. This article will show you how to make one easily.</p>

<br /><a href="http://www.useragentman.com/examples/progress/dnfmomd.html" class="exampleLink">A Really Cool Photo Gallery Example of Image Caching With HTML5 <code>&lt;progress&gt;</code></a>
<h2>Caching Images.</h2>
<p><strong>Before we do anything, we need to know how to cache images.</strong>  Developers have been using the DOM Level 0 <code>Image()</code> object to cache images since almost the beginning of JavaScript&#8217;s history.  Basically it involves creating a new <code>Image()</code> object, and then setting the src to be URL of the image.</p>
<blockquote class="code">
<pre>
var im = new Image();
im.src = "http://www.useragentman.com/images/zoltFront.jpg";
</pre>
</blockquote>
<p>Back in the 1990&#8242;s, this technique was used a lot to cache images involved in animation of hover states.  A good example of this is on the <a href="http://web.archive.org/web/19970715114207/http://www.netcom.ca/netcom/about.html">old Netcom Canada website circa 1997</a> (available today thanks to the magic of <a href="http://wayback.archive.org/web/">The Way Back Machine</a>).  If you mouseover any of the navigation links in the header, you&#8217;ll see the image button change in appearance.  In order for this animation to happen as soon as the user hovers over the links, the page must cache all the hover-state images, so that the user doesn&#8217;t see any flicker on-hover as the image is loading.  Modern developers would use <a href="http://www.alistapart.com/articles/sprites">CSS sprites</a> to do this, but back in the day, this was the only way to go.</p>
<p>But how can one use this technique to update a progress bar?  The <code>Image()</code> object has a <code>load</code> event, so we can use that to increment a progress bar.  To simplify this process, I have created a very simple JavaScript library, <a href="https://github.com/zoltan-dulac/imageCache">imageCache.js</a>, that will cache an array of image URLs and fire off two events: one when each image is loaded, and one where the whole array is loaded.  Image caching is as simple as this:</p>
<blockquote class="code">
<pre>
var s=["images/1.jpg", "images/2.jpg", "images/3.jpg"];
<span class="hilite">imageCache.pushArray(s, <em>loadImageEvent</em>, <em>loadAllEvent</em>);</span>
</pre>
</blockquote>
<p><code>loadImageEvent</code> is a callback that is called every time an image is loaded, and <code>loadAllEvent</code> is called when all of the images are loaded.</p>
<p><a href="https://github.com/zoltan-dulac/imageCache" class="exampleLink">Download <code>imageCache.js</code> from GitHub.</a></p>
<h2>Using <code>&lt;progress&gt;</code> to Show When Each Image Has Loaded</h2>
<p>In the image gallery example at the beginning of this article, we have 28 images that we want to load into cache before showing the content of the page.  We also want a progress bar to show these images loading.  In order to do this, we need to make two containers: one that holds the progress bar and one that holds the content:</p>
<blockquote class="code">
<pre>
&lt;-- The Progress Bar Container --&gt;
&lt;div id="progressContainer"&gt;
    Loading: &lt;br /&gt;
    &lt;progress id="loader" max="28" value="0"&gt;
       &lt;strong&gt;Loaded &lt;span id="value"&gt;0&lt;/span&gt;/28&lt;/strong&gt;
    &lt;/progress&gt;
&lt;/div&gt;

&lt;-- The Content Container --&gt;
&lt;div id="content"&gt;
   &lt;!-- this should contain the content for the rest of the site --&gt;
&lt;/div&gt;
</pre>
</blockquote>
<p>You would then create a JavaScript snippit that would pre-cache all the images.  What follows is an example that uses jQuery to do this, but since <strong>the imageCache.js library itself doesn&#8217;t need jQuery</strong>, feel free to use any framework you like (or lack of framework if you are &#8220;<a href="http://www.penny-arcade.com/comic/2008/03/12">Teh Hardcorez</a>&#8220;):</p>
<blockquote class="code">
<pre>
var dnfmomd = new function () {
   var me = this;

   var $loader,
       currentImage = 0;

   me.init = function () {

      var s = [];

      for (var i=1; i&lt;=28; i++) {
         s.push('images/dnfmomd/' + i + '.jpg');
      }
      $loader = $('#loader');

      $loader.max = s.length;
      imageCache.pushArray(s, <span class="hilite">loadImageEvent</span>, <span class="hilite2">loadAllEvent</span>);

   }

<span class="hilite">   function loadImageEvent() {
      val = parseInt($loader.attr('value'));
      val++;
      $loader.attr('value', val);
   }</span>

<span class="hilite2">   function loadAllEvent() {
      $('body').addClass('loaded');
      showImage(1, true);
   }</span>

   ....

}

/*
 *  Use $(window).load() instead of $(document).ready() because we wan't to start caching images
 *  as soon as the progress bar images are loaded.
 */

$(window).load(dnfmomd.init)
</pre>
</blockquote>
<p>Note that progress bar&#8217;s value is increased every time an image is loaded, and when all the images are loaded, we add the <code>loaded</code> class to the body.  This will result in the progress bar disappearing and the content becoming visible, due to this CSS in the page:</p>
<blockquote class="code">
<pre>
  #content {
     display: none;
  }

  body.loaded #content {
     display: block;
  }

  body.loaded #progressContainer {
     display: none !important;
  }
</pre>
</blockquote>
<h2>Can We Show Other Things Loading in the Progress Bar Besides Images?</h2>
<p>It is possible to show CSS and JavaScript in the progress bar using <a href="http://yepnopejs.com/">yepnope.js</a>.  It is a little bit more involved, but very doable (I have done it before), and I leave it as an exercise to the reader to do it.  Post it below, and I&#8217;ll give you full geek-cred.  If no one does it, I will probably take some time and publish an example in a few weeks, but I thought it would be neat to offer up a little challenge. :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2012/01/16/caching-images-with-javascript-and-html5-progress-bars/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cross Browser HTML5 Progress Bars In Depth</title>
		<link>http://www.useragentman.com/blog/2012/01/03/cross-browser-html5-progress-bars-in-depth/</link>
		<comments>http://www.useragentman.com/blog/2012/01/03/cross-browser-html5-progress-bars-in-depth/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 07:08:54 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[CSS3]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[gradients]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Polyfills]]></category>
		<category><![CDATA[progress]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=4016</guid>
		<description><![CDATA[<img src="http://www.useragentman.com/blog/wp-content/uploads/2012/01/intro.png" />  As a web application developer,<strong> progress bars are great when you want to show the user that some action is happening,</strong> especially when it can take a long time.  Creating them is easy with the HTML5 <code>&#60;progress&#62;</code> tag.  This article will discuss <strong>how this tag is rendered by default</strong> in all operating systems and browsers and how to <strong>style the <code>progress</code> tag with CSS</strong>, even in browsers that don't officially support the it.  It will also show some <strong>interesting examples using advanced CSS3 techniques.</strong>]]></description>
			<content:encoded><![CDATA[<div class="importantNotes">
<h3>Note:</h3>
<p>The stylesheet for the polyfill was not included correctly when this post was first published, and as a result, the examples below were not showing up correctly on IE7-8 and Safari 5.1+.  The problem has been corrected.</p>
</div>
<p><div id="attachment_4224" class="wp-caption alignleft" style="width: 260px"><img src="http://www.useragentman.com/blog/wp-content/uploads/2012/01/intro.png" alt="" title="intro" width="250" height="180" class="size-full wp-image-4224" /><p class="wp-caption-text">Screenshots of HTML5 progress bars with different styles applied.  Details given below.</p></div> As a web application developer,<strong> progress bars are great when you want to show the user that some action is happening,</strong> especially when it can take a long time.  They can be <strong>animated</strong> (like the one in Gmail does when it shows the user how long it is going to take for it to load and initialize), <strong>or static</strong> (like some shopping cart applications have to show the user how many pages it will take to check out an order).  I used to <a href="http://css-tricks.com/css3-progress-bars/">create progress bars using <code>&lt;div&gt;</code> tags, CSS and a litle bit of math</a>, but now I like to do it the HTML5 way using the <code>&lt;progress&gt;</code> tag.  This article will discuss <strong>how this tag is rendered by default</strong> in all operating systems and browsers and how to <strong>style the <code>progress</code> tag with CSS</strong>, even in browsers that don&#8217;t officially support the it.  It will also discuss some interesting <strong>limitations of all the browser implementations</strong> amd show some <strong>interesting examples using advanced CSS3 techniques.</strong></p>
<h2>The HTML: Simple</h2>
<p>The HTML for a Progress bar is dead simple:</p>
<blockquote class="code">
<pre>
&lt;progress max="100" value="60"&gt;
  &lt;strong&gt;Progress: 60% done.&lt;/strong&gt;
&lt;/progress&gt;
</pre>
</blockquote>
<div class="example">
<progress max="100" value="60"><strong>Progress: 60% done.</strong></progress>
</div>
<p><strong>Note that the HTML inside the <code>&lt;progress&gt;</code> tag is the fallback for browsers that do not support it.</strong>  That, unfortunately, includes all versions of IE and Safari so far, as well older versions of Firefox (5.x and lower) and Opera (10.x and lower).  Although the fallback is acceptable, we can go a step further and use <strong><a href="http://lea.verou.me/">Lea Verou&#8217;s</a> excellent <a href="http://lea.verou.me/2011/07/a-polyfill-for-html5-progress-element-the-obsessive-perfectionist-way/"><code>&lt;progress&gt;</code> tag polyfill</a></strong>, which adds pretty much full-support for all of these browsers <strong>except for Safari 5 and lower</strong> (so you should <em><strong>always put in the fallback HTML just to be on the safe side</strong></em>).  Let&#8217;s take a look at these screenshots to see what how <code>&lt;progress&gt;</code> looks across the browserverse:</p>
<table class="dataTable">
<thead>
<tr>
<th></th>
<th>Windows 7</th>
<th>Windows XP</th>
<th>Mac OS X</th>
<th>Ubuntu Linux</th>
</thead>
<tbody>
<tr>
<th>Firefox</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultFirefoxWin.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultFirefoxWinXP.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultFirefoxMac.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultFirefoxLinux.png" alt=""  /></td>
</tr>
<tr>
<th>Chrome</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultChromeWin.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultChromeWinXP.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultChromeMac.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultChromeLinux.png" alt=""  /></td>
</tr>
<tr>
<th>IE7+ (polyfill)</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultSafariWin_poly.png" alt=""  /></td>
<td colspan="3" class="na">N/A</td>
</tr>
<tr>
<th>Safari 5.1+ (polyfill)</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultSafariWin_poly.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultSafariWin_poly.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultSafariWin_poly.png" alt=""  /></td>
<td class="na">N/A</td>
</tr>
<tr>
<th>Opera</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultOperaWin.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultOperaWin.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultOperaMac.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/defaultOperaLinux.png" alt=""  /></td>
</tr>
</tbody>
</table>
<p>Note that:</p>
<ul>
<li>Firefox and Chrome will render the progress bar the same way that the host operating system would &#8230; except for Chrome for Linux, which uses it&#8217;s own custom style (thanks to <a href="http://blog.oldworld.fr/">Mounir Lamouri</a> for correcting me on this exception).</li>
<li>The color of the Opera progress value is always green (more on this later).</li>
<li>The browsers that use the polyfill all render the progress bar with a nice bluish gradient effect</li>
</ul>
<p>A progress bar <strong>can also have an <em>&#8220;indeterminate&#8221;</em> state</strong>, which happens when there is <strong>no value attribute</strong>. </p>
<blockquote class="code">
<pre>
&lt;progress max="100"&gt;
  &lt;strong&gt;Progress: 60% done.&lt;/strong&gt;
&lt;/progress&gt;
</pre>
</blockquote>
<div class="example">
<progress max="100" ><strong>Progress: 60% done.</strong></progress>
</div>
<p>This effect is used to show that the state of progress is currently unknown (e.g. how long it will take for a web server to initiate the download of a file if is generating it on the fly).  How this looks varies from browser to browser as well.</p>
<table class="dataTable">
<thead>
<tr>
<th></th>
<th>Windows 7</th>
<th>Windows XP</th>
<th>Mac OS X</th>
<th>Ubuntu Linux</th>
</thead>
<tbody>
<tr>
<th>Firefox</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterFirefoxWin.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterFirefoxWinXP.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterFirefoxMac.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterFirefoxLinux.png" alt=""  /></td>
</tr>
<tr>
<th>Chrome</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterChromeWin.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterChromeWinXP.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterChromeMac.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterChromeLinux.png" alt=""  /></td>
</tr>
<tr>
<th>IE7+ (polyfill)</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterSafariWin_poly.png" alt=""  /></td>
<td colspan="3" class="na">N/A</td>
</tr>
<tr>
<th>Safari 5.1+ (polyfill)</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterSafariWin_poly.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterSafariWin_poly.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterSafariWin_poly.png" alt=""  /></td>
<td class="na">N/A</td>
</tr>
<tr>
<th>Opera</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterOperaWin.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterOperaWin.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterOperaMac.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/indeterOperaLinux.png" alt=""  /></td>
</tr>
</tbody>
</table>
<p>Note that:</p>
<ul>
<li>Opera is the only browser that doesn&#8217;t distinguish between a progress bar with an indeterminate state and one with a value of zero.</li>
<li>All of the other browsers (including the ones that use the polyfill) animate the indeterminate states.  (I have opted to not show all the animations here to avoid readers getting seizures &#8230; I hear that would be a bad thing).</li>
</ul>
<h2>But I Want To Style Them My Way!</h2>
<p>If you are particular in how you want your <code>&lt;progress&gt;</code> tags to look, the good news is that <strong>you can pretty much style them any way you want</strong>.  You must, however, <strong>be aware about the browser quirks</strong> that can trip you up &#8230; and it isn&#8217;t all IE&#8217;s fault this time!  Follow this three-to-four-step process, and you&#8217;ll be styling progress bars in your sleep in no time:</p>
<h3>Step 1: Turn off default styling</h3>
<p>The first step is to turn off the default styling in all browsers:</p>
<blockquote class="code">
<pre>
progress,          /* All HTML5 progress enabled browsers */
progress[role]     /* polyfill */
{

	/* Turns off styling - not usually needed, but good to know. */
	appearance: none;
	-moz-appearance: none;
	-webkit-appearance: none;

	/* gets rid of default border in Firefox and Opera. */
	border: none;

	/* Needs to be in here for Safari polyfill so background images work as expected. */
	background-size: auto;

	/* Dimensions */
	width: 400px;
	height: 60px;

}

/* Polyfill */
progress[role]:after {
	background-image: none; /* removes default background from polyfill */
}

/* Ensure fallback text doesn't appear in polyfill */
progress[role] strong {
	display: none;
}
</pre>
</blockquote>
<div class="example">
<progress class="example1 a" min="0" max="100" value="50">
<strong>Progress: 60% done.</strong>
</progress>
</div>
<p>Simple stuff: remove the border and add a specific width and height.  I added the second rule to remove the background image inserted by the polyfill&#8217;s stylesheet, but if you wanted, you can  modify the polyfill&#8217;s stylesheet directly (or leave it out completely if you elect not to use the polyfill).   The final rule is to ensure the polyfill doesn&#8217;t display the fallback content &mdash; it assumes that is always wrapped in a <code>&lt;strong&gt;</code> tag, so this may be something you should keep in mind when setting the default content (if you don&#8217;t like using a <code>&lt;strong&gt;</code> tag as a wrapper for your fallback content, use whatever tag you like).</p>
<p>Note that the <code>appearance</code> property (and its vendor-specific brethren) are there to turn off the default operating-system styling on the progress bar &mdash; it doesn&#8217;t seem like it is really necessary, but I put it here for reference in case it becomes mandatory in the future.</p>
<h3>Step 2: The Progress Bar Background.</h3>
<p>Now let&#8217;s change the background color of the progress bar to a light red.  </p>
<blockquote class="code">
<pre>
progress,                          /* Firefox  */
progress[role][aria-valuenow] {    /* Polyfill */
   background: #ffeeee !important; /* !important is needed by the polyfill */
}

/* Chrome */
progress::-webkit-progress-bar {
    background: #ffeeee;
}
</pre>
</blockquote>
<div class="example">
<progress class="example1 a b" min="0" max="100" value="50"></progress>
</div>
<p>Notice that with Firefox and the polyfilled browsers, all you need to do is change the background of just the <code>progress</code> tag itself, while in Chrome (and I assume future versions of Safari) it is necessary to use the <code>-webkit-progress-bar</code> pseudo-element. Note that even though the code inside these rules are the same,<strong> you cannot put all of these selectors in one rule</strong>: doing so breaks Firefox and Opera (so much for degrading gracefully).</p>
<h3>Step 3: The Progress Bar Value</h3>
<p>Now let&#8217;s change the color of progress bar value to black.  The CSS is a <em>wee bit longer than it really should be</em>:</p>
<blockquote class="code">
<pre>
/* Firefox */
progress::-moz-progress-bar {
    background: black;
}

/* Chrome */
progress::-webkit-progress-value {
    background: black;
}

/* Polyfill */
progress[aria-valuenow]:before  {
    background: black;
}
</pre>
</blockquote>
<div class="example">
<progress class="example1 a b c" min="0" max="100" value="50"></progress>
</div>
<p>Yes, three rules to rule them all!  Again, putting them all together in one selector breaks every browser on the planet (including the polyfilled ones), so we have to write three separate rules with the same CSS properties in them! &lt;sarcasm&gt;Yaaayyy!!!!&lt;/sarcasm&gt;</p>
<p><strong>Note that there is no way that I know of to style the progress bar value in Opera 11.52 and lower.</strong>  It just stays the same green no matter what you do. :-( If anyone is reading this and knows otherwise, I would be indebted to you to let me know how.</p>
<h3>Step 4: The Indeterminate Value</h3>
<p>This part is optional, and I would only put these rules in if I know I&#8217;ll need a style for the indeterminate value (not all applications need it):</p>
<blockquote class="code">
<pre>
/* Firefox */
progress:not([value])::-moz-progress-bar {
  background-image:  url(../images/indeter.gif);
}

/* Chrome */
progress:not([value])::-webkit-progress-bar {
  background-image:  url(../images/indeter.gif);
}

/* Polyfill - IE */
progress[role]{
	background-image: url(../images/indeter.gif) !important;
}

/* Polyfill - Safari */
progress:not([value])  {
	background-image: url(../images/indeter.gif) !important;
	background-size: auto;  /* Needs to be in here for Safari */
}
</pre>
</blockquote>
<div class="example">
<progress class="example1 a b c d" min="0" max="100"></progress>
</div>
<p>It even works in Opera! Note that the <code>background-size</code> must be set to <code>auto</code> in order to override the default style in the polyfill.  :-)</p>
<p><a href="http://www.useragentman.com/examples/progress/" class="exampleLink">See the above CSS in action in a &#8220;clean room&#8221; page</a></p>
<h2>That&#8217;s Too Basic! I Want Fancy-Pants&trade; Progress Bars</h2>
<p>So, now that you know the basics, let&#8217;s take a look at some more complicated and interesting progress bars:</p>
<h3>Two Image Effect</h3>
<p>This progress bar uses two versions of the same image (one grey-scale, one color) to differentiate between the progress bar background and value: </p>
<div class="example">
<progress class="example2" min="0" max="100" value="60"></progress>
</div>
<p><a href="http://www.useragentman.com/examples/progress/uam.html" class="exampleLink">See the above example in action in a &#8220;clean room&#8221; page</a></p>
<h3>Gradients</h3>
<p>Note that  not only can you use <code>background-color</code>s and <code>-image</code>s, but also use the variety of gradients that are available for developers today in supported browsers (this does <strong>not</strong> include IE9 and lower).  To prove this, I took Chris Croyer beautiful <code>&lt;div&gt;</code> style progress bars from his <a href="http://css-tricks.com/css3-progress-bars/">blog post on CSS3 based progress bars</a> and HTML5-ified&trade; them here:</p>
<div class="example">
<progress class="example3" min="0" max="100" value="60"></progress>
</div>
<div class="example">
<progress class="example4" min="0" max="100" value="60"></progress>
</div>
<p>Unfortunately, due to CSS gradients being implemented by the browser vendors using vendor-specific prefixes, the CSS tends to be a wee long.  Here is the CSS of the first example (scroll the code to see the whole lot of it):</p>
<blockquote class="code shortened">
<pre>
/*
 * Gradient Shadow
 */

/* All HTML5 progress enabled browsers */
progress.example3 {

	/* Turns off styling - not usually needed, but good to know. */
	appearance: none;
	-moz-appearance: none;
	-webkit-appearance: none;
	/* gets rid of default border in Firefox and Opera. */
	border: solid #cccccc 5px;
	border-radius: 10px;
	/* Dimensions */
	width: 238px;
	height: 45px;
}

/* Polyfill */
progress.example3[role]:after {
	background-image: none; /* removes default background from polyfill */
}

/*
 * Background of the progress bar background
 */

/* Firefox and Polyfill */
progress.example3 {
	background: #cccccc !important; /* !important only needed in polyfill */
}

/* Chrome */
progress.example3::-webkit-progress-bar {
	background: #cccccc;
}

/*
 * Background of the progress bar value
 */

/* Firefox */
progress.example3::-moz-progress-bar {
	border-radius: 5px;
	background-image: -moz-linear-gradient(
		center bottom,
		rgb(43,194,83) 37%,
		rgb(84,240,84) 69%
	);
}

/* Chrome */
progress.example3::-webkit-progress-value {
	border-radius: 5px;
	background-image: -webkit-gradient(
		linear,
		left bottom,
		left top,
		color-stop(0, rgb(43,194,83)),
		color-stop(1, rgb(84,240,84))
	);
	background-image: -webkit-linear-gradient(
		center bottom,
		rgb(43,194,83) 37%,
		rgb(84,240,84) 69%
	);
}

/* Polyfill */
progress.example3[aria-valuenow]:before {
	border-radius: 5px;
	background-image: -moz-linear-gradient(
		center bottom,
		rgb(43,194,83) 37%,
		rgb(84,240,84) 69%
	);
	background-image: -ms-linear-gradient(
		center bottom,
		rgb(43,194,83) 37%,
		rgb(84,240,84) 69%
	);
	background-image: -o-linear-gradient(
		center bottom,
		rgb(43,194,83) 37%,
		rgb(84,240,84) 69%
	);

}
</pre>
</blockquote>
<p>Note that I did not use the <a href="http://msdn.microsoft.com/en-us/library/ms532997%28v=vs.85%29.aspx"><code>Gradient</code> filter</a> to polyfill CSS3 gradients in IE6-9.  This is because Visual Filters don&#8217;t work in CSS3 pseudo-elements like <code>:before</code> or <code>:after</code>.  Oh well.</p>
<p><a href="http://www.useragentman.com/examples/progress/striping.html" class="exampleLink">See the above CSS in action in a “clean room” page</a></p>
<h3>Monkeys!</h3>
<p>What blog post about HTML5 progress tags would be complete without monkeys?  These simians appear in all browser except for IE8 and lower (as explained below).  </p>

<div class="example">
<progress class="monkey" min="0" max="100" value="60"></progress><div class="after"></div>
</div>
<p>Apologies to the great <a href="http://banksy.co.uk/">Banksy</a> &mdash; it&#8217;s not <a href="http://www.guyhepner.com/index.php?url=images/get/509x397/3087/banksy-paintings-laugh-now-but-one-day-we-ll-be-in-charge.jpg">his monkey</a> but one grabbed from <a href="http://www.animatedgif.net/clockscounters/clockscounters3.shtml">this Animated GIF site</a> and converted into a <a href="http://www.alistapart.com/articles/sprites">CSS sprite</a> using <a href="http://blog.somepixels.net/">André Gil&#8217;s</a> super-cool <a href="http://labs.andregil.net/Gif2TileSet/Gif2TileSet.html">Gif2TileSet tool</a>.  I took this sprite and animated the monkey using blitting whenever the progress bar changes values (thanks to my friend and colleague <a href="http://noel.tibbles.ca/">Noel Tibbles</a> for turning me on to this technique).</p>
<p>Note the HTML has an extra <code>&lt;div&gt;</code> tag so the monkey has a place to live:</p>
<blockquote class="code">
<pre>
&lt;progress class="monkey" min="0" max="100" value="60"&gt;&lt;/progress&gt;
&lt;div class="after"&gt;&lt;/div&gt;
</pre>
</blockquote>
<p><strong>I wish that I could have used <code>:after</code> (or <code>::after</code>) rules</strong> instead, but these pseudo-elements <strong>don&#8217;t work with the <code>progress</code> tags in <em>any</em> browser that doesn&#8217;t use the polyfill</strong>.  And no, <code>:before</code> doesn&#8217;t work either.  I have no idea why it doesn&#8217;t work, but it&#8217;s a shame &mdash; using them would be perfect to get rid of the extra markup.</p>
<p>The CSS that makes the monkey animate when the progress bar changes values is here:</p>
<blockquote class="code">
<pre>
progress.monkey[value="0"] +  .after{
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif');
} 

progress.monkey[value^="1"] +  .after {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -77px ;
}

progress.monkey[value^="2"] +  .after {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -154px ;
}

progress.monkey[value^="3"] +  .after,
progress.monkey[value="100"] +  .after  {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -231px !important ;
}

progress.monkey[value^="4"] +  .after {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -308px ;
}

progress.monkey[value^="5"] +  .after {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -385px ;
}

progress.monkey[value^="6"] +  .after {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -462px ;
}

progress.monkey[value^="7"] +  .after {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -539px ;
}

progress.monkey[value^="8"] +  .after {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -616px ;
}

progress.monkey[value^="9"] +  .after {
	background: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif') 0  -693px ;
}
</pre>
</blockquote>
<p>Each of these rules are applied when the first digit changes in the progress bar, which is done using the ^= attribute rules. This works because the progress bar goes from 0 &#8211; 100 and the progress bar increments by 10.  They monkeys don&#8217;t appear in IE8 and under because of it&#8217;s lack of support of the ^= attribute selector (but it works well in IE9).</p>
<p>Note that <strong>this would be much easier if CSS allowed us to combine the CSS3 <code>calc()</code> and <code>attr()</code> attributes together</strong> like <a href="http://lea.verou.me/2010/09/on-attr-and-calc/">Lea Verou dreams about in one of her blog posts</a>:</p>
<blockquote class="code">
<pre>
/*
 * Don't try this - it doesn't work in any browser, but it would be nice if it did.
 */

progress.monkey::after {
   background-image: url('/blog/wp-content/uploads/2011/12/monkeyBlit.gif');
   background-position-x: 0;
   background-position-y: calc(-77 * attr(value), 'px');
}
</pre>
</blockquote>
<p>Hopefully this will come to pass in the future.</p>
<p><a href="http://www.useragentman.com/examples/progress/blit.html" class="exampleLink">See the above CSS in action in a “clean room” page</a></p>
<h3>Speedometer</h3>
<p>My last example is radically different than the others.  How about we apply the speedometer metephor to the progress bar with some fancy-pants CSS3?   This example in all browsers except IE8 and lower (due to lack of support for native CSS3 <code>transform</code>) </p>

<div class="example speedometer">
<div id="progressContainer">
  <progress id="rot" class="example_r" min="0" max="100" value="60"></progress>
  <div data-arrow-for="rot" class="arrow"><img src="/blog/wp-content/uploads/2012/01/hand.png" /></div>
</div>
</div>
<p>The CSS is similar to the monkey example in that I add an extra <code>&lt;div&gt;</code> after the progress tag, except that it has an image of a pointer inside of it.</p>
<blockquote class="code">
<pre>
&lt;div id="progressContainer"&gt;
  &lt;progress id="rot" class="example_r" min="0" max="100" value="60"&gt;&lt;/progress&gt;
  &lt;div data-arrow-for="rot" class="arrow"&gt;&lt;img src="/blog/wp-content/uploads/2012/01/hand.png" /&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
</blockquote>
<p>I wrapped both these tags inside a relatively positioned container <code>&lt;div&gt;</code>.  This is so I could absolutely position both the progress bar and the arrow in order for them to line up properly.  I make the progress bar into a semi-circle by using <code>border-radius</code> and part of a <a href="http://www.flickr.com/photos/listener42/4991330345/">photo from Flickr user &#8216;listener42&#8242;</a> &#8230;</p>
<blockquote class="code">
<pre>
progress.example_r {

	/* gets rid of default border in Firefox and Opera. */
	border: solid 1px black;
	display: inline-block;

	/* Produces the semi-circle */
	<span class="hilite">border-radius: 238px 238px 0 0;</span>

	/* Dimensions */
	width: 238px;
	height: 126px;
	padding: 0;
}
</pre>
</blockquote>
<p>&#8230; and make the arrow rotate as the progress bar increments by using CSS transforms: </p>
<blockquote class="code shortened">
<pre>
progress.example_r[value="0"] + .arrow {
	-moz-transform: rotate(270deg);
	-webkit-transform: rotate(270deg);
	-o-transform: rotate(270deg);
	-ms-transform: rotate(270deg);
}

progress.example_r[value^="1"]:not([value="1"]):not([value="100"]) + .arrow {
	-moz-transform: rotate(288deg);
	-webkit-transform: rotate(288deg);
	-o-transform: rotate(288deg);
	-ms-transform: rotate(288deg);
}

progress.example_r[value^="2"]:not([value="2"]) + .arrow {
	-moz-transform: rotate(306deg);
	-webkit-transform: rotate(306deg);
	-o-transform: rotate(306deg);
	-ms-transform: rotate(306deg);
}

progress.example_r[value^="3"]:not([value="3"]) + .arrow {
	-moz-transform: rotate(324deg);
	-webkit-transform: rotate(324deg);
	-o-transform: rotate(324deg);
	-ms-transform: rotate(324deg);
}

progress.example_r[value^="4"]:not([value="4"]) + .arrow {
	-moz-transform: rotate(342deg);
	-webkit-transform: rotate(342deg);
	-o-transform: rotate(342deg);
	-ms-transform: rotate(342deg);
}

progress.example_r[value^="5"]:not([value="5"]) + .arrow {
	-moz-transform: rotate(360deg);
	-webkit-transform: rotate(360deg);
	-o-transform: rotate(360deg);
	-ms-transform: rotate(360deg);
}

progress.example_r[value^="6"]:not([value="6"]) + .arrow {
	-moz-transform: rotate(378deg);
	-webkit-transform: rotate(378deg);
	-o-transform: rotate(378deg);
	-ms-transform: rotate(378deg);
}

progress.example_r[value^="7"]:not([value="7"]) + .arrow {
	-moz-transform: rotate(396deg);
	-webkit-transform: rotate(396deg);
	-o-transform: rotate(396deg);
	-ms-transform: rotate(396deg);
}

progress.example_r[value^="8"]:not([value="8"]) + .arrow {
	-moz-transform: rotate(414deg);
	-webkit-transform: rotate(414deg);
	-o-transform: rotate(414deg);
	-ms-transform: rotate(414deg);
}

progress.example_r[value^="9"]:not([value="9"]) + .arrow {
	-moz-transform: rotate(432deg);
	-webkit-transform: rotate(432deg);
	-o-transform: rotate(432deg);
	-ms-transform: rotate(432deg);
}

progress.example_r[value="100"] + .arrow {
	-moz-transform: rotate(450deg);
	-webkit-transform: rotate(450deg);
	-o-transform: rotate(450deg);
	-ms-transform: rotate(450deg);
}
</pre>
</blockquote>
<p>Again, the CSS would be much smaller in size if I could use <code>calc()</code> and <code>attr()</code> together, but again, oh well.   Also note that this example doesn&#8217;t work in Opera very well because we cannot turn of the green in the progress bar value.  :-(</p>
<p><a href="http://www.useragentman.com/examples/progress/rotate.html" class="exampleLink">See the above CSS in action in a “clean room” page</a></p>
<h2>Summary of Gotchas</h2>
<p>As mentioned before, there are a few annoyances I have found with they way the browsers have implemented HTML5 progress bars:</p>
<ol>
<li>You cannot use <code>:before</code>/<code>::before</code> or <code>:after</code>/<code>::after</code> pseudo-elements on the <code>progress</code> element.  Why this is not allowed is unclear to me, and I hope this is allowed in the future.</li>
<li>Safari 5.0 and lower cannot use the polyfill, so you should always use the fallback HTML inside the <code>&lt;progress&gt;</code> tag.</li>
<li>It seems like it is impossible to change Opera&#8217;s progress bar style to anything besides green.</li>
<li>There is a <strong>small bug in the polyfill</strong> when applying borders to the progress bar.  I have <a href="https://github.com/zoltan-dulac/HTML5-Progress-polyfill">a fix</a> that has been <a href="https://github.com/LeaVerou/HTML5-Progress-polyfill/pull/6">submitted as a pull request</a> and I assume being reviewed, but in the meantime, you can <a href="https://github.com/zoltan-dulac/HTML5-Progress-polyfill">get my forked version of the polyfill (with the bug fix) on GitHub</a>.</li>
</ol>
<h2>Help Me Keep This Page Up-To-Date!</h2>
<p>If you find out more information about the HTML5 <code>progress</code> tag, I&#8217;d love to hear from you!  Please let me know in the comments below.  I will add relevant information to the above article and credit you fully. :-)</p>
<p><script src="/shared/js/lea.verou.me/progressPolyfill/progress-polyfill.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2012/01/03/cross-browser-html5-progress-bars-in-depth/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Cross Browser CSS cursor Images In Depth</title>
		<link>http://www.useragentman.com/blog/2011/12/21/cross-browser-css-cursor-images-in-depth/</link>
		<comments>http://www.useragentman.com/blog/2011/12/21/cross-browser-css-cursor-images-in-depth/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 05:34:31 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[cursor]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[custom cursors]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[Internet Explorer]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=3893</guid>
		<description><![CDATA[<img src="/blog/wp-content/uploads/2011/12/intro.png" /> When used properly, custom CSS cursors can add a little bit of polish to your web sites and applications.  However, doing this in a cross browser way can be a little confusing unless you know all the gotchas, and this article will go into depth about them.   We will also explore issues such as when to use custom cursors, performance, what makes good cursor design, cursor file formats, and cursor size.]]></description>
			<content:encoded><![CDATA[
<!--
        This notice is required for the CanvasPainer widget below.

	Copyright (c) 2005, 2006 Rafael Robayna

	Permission is hereby granted, free of charge, to any person obtaining 
	a copy of this software and associated documentation files (the "Software"), 
	to deal in the Software without restriction, including without limitation 
	the rights to use, copy, modify, merge, publish, distribute, sublicense, 
	and/or sell copies of the Software, and to permit persons to whom the Software 
	is furnished to do so, subject to the following conditions:
	
	The above copyright notice and this permission notice shall be included
	in all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
	EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
	OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
	IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
	DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
	OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
	OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

	Additional Contributions by: Morris Johns
-->


<div id="canvasPainter">
<div id="controls">
  <div class="ctr_btn" id="btn_1" >brush 2</div> 
  <div class="ctr_btn" id="btn_2" >line</div> 
  <div class="ctr_btn" id="btn_3" >rectangle</div> 
  <div class="ctr_btn" id="btn_4" >circle</div> 
  <div class="ctr_btn" id="btn_5" >clear</div> 
  <div class="ctr_btn" id="btn_9">new</div>
  <input class="color" id="color" value="#ff3333"></div>
<canvas id="canvas" width="200" height="200"></canvas>
<canvas id="canvasInterface" width="200" height="200"></canvas>
<p class="description"><small>Paint widget a remix of <a href="http://caimansys.com/painter/">CanvasPainter</a> © <a href="http://caimansys.com/">Rafael Robayna</a></small></p>
</div>
<p><strong>If you are using a desktop browser (except for Opera), play with the paint widget on the left.</strong>  When you select a tool and mouse over the white canvas, your mouse arrow will change to a custom cursor representing that tool (&agrave; la Photoshop or The GIMP).  This is not done by creating a DOM object and moving it to the mouse&#8217;s coordinates &mdash; we are using CSS to do it using the <code>cursor</code> property&#8217;s <code>url()</code> function. <strong> When used properly, custom CSS cursors can add a little bit of polish</strong> to your web sites and applications.  However, <strong>doing this in a cross browser way can be a little confusing</strong> unless you know all the gotchas, and this article will go into depth about them.   We will also explore issues such as <strong>when to use custom cursors, performance, what makes good cursor design, cursor file formats, and cursor size.</strong></p>
<h2>When Should I Use Custom Cursors Instead of the Built-in Ones?</h2>
<p>In general, CSS cursors (built-in or custom) should be used as a hint to the user as to what action the mouse can perform.  Let&#8217;s take a look at an example that doesn&#8217;t use custom cursors to illustrate a common use-case: drag and drop.  To give users a visual cue that an item is draggable, it is common practice to set an object&#8217;s CSS <code>cursor</code> property to <code>move</code>.  Mouse over the object draggable object below to see how this works. </p>
<div id="container">
<a href="#" id="toDrag" draggable="true">Drag me!</a>
</div>
<p>This is done with the following CSS:</p>
<blockquote class="code">
<pre>
a[draggable="true"] {
    cursor: move;
}
</pre>
</blockquote>
<p>The code above ensure that when a user &#8220;mouses over&#8221; a link with the HTML5 Drag and Drop &#8220;draggable&#8221; attribute, the <code>move</code> cursor appears.  It is a great way to help the user &#8220;figure out&#8221; how to use the user interface with minimal instruction.  A list of the built-in cross-browser cursor property values can be seen at <a href="http://www.quirksmode.org/css/cursor.html">CSS2 Cursor Style Page</a>.</p>
<p>The built-in cursors are great, but there are a few things to keep in mind.</p>
<ul>
<li><strong>Built-in cursors may look different depending on what browser/operating system is being used</strong>.  For example, some browsers (e.g. Firefox on Windows 7) will show the <code>move</code> cursor as a four-pointed arrow (<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/move_cursor.png" alt="[Four-Pointed Arrow Cursor]" class="inline" />) while others (e.g. Firefox on Mac OS X) will show a hand (<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/cursor-hand.png" alt="[Hand Cursor]" class="inline" />).  Using custom cursors, you can ensure all applications are using the same cursor for a more consistent expeience.  The example below is the same as the one above, except in all browsers, you will see the a hand icon.
<div id="container2">
<a href="#" id="toDrag2" draggable="true">Drag me!</a>
</div>
</li>
<li><strong>Not all browsers support all the same &#8220;built-in&#8221; cursors, and custom cursors allows you to add support for them.</strong> For example, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=258960">while Firefox on Windows doesn&#8217;t support <code>context-menu</code></a>, it seems to be the only browser that <a href="https://developer.mozilla.org/en/CSS/-moz-zoom-in">supports the zoom-in and -out cursors</a>.  Using custom cursors, you can implement all of these in all browsers.</li>
<li><strong>There may not be a built-in cursor for the use-case you need to solve.</strong>  A good example is in the paint widget at the beginning of this article &mdash; none of those cursors exist natively in any browser.</li>
<li><strong>It&#8217;s nice to design your own cursors</strong>, since sometimes the built-in ones may be a little basic looking (If you do this, please keep in mind that users are used to the built in ones, so your custom cursor shouldn&#8217;t look too much different than them if you want your application to be easy-to-use).
</ul>
<h2>The CSS of Custom Cursors</h2>
<p>Here is some sameple CSS code that will show custom cursor when the user mouses over a <code>div</code> with an id of <code>dragMe</code>.  If the browser doesn&#8217;t do custom cursors (like Opera), the cursor fallback to the built-in <code>move</code> cursor.</p>
<blockquote class="code">
<pre>
#dragMe {
    cursor: url('customMoveCursor.cur'), move;
}
</pre>
</blockquote>
<p><strong>As long as your cursor is in the same directory as your stylesheet, and as long as it is an uncompressed .CUR file, it&#8217;s as simple as that.</strong> Note that <a href="http://en.wikipedia.org/wiki/ICO_%28file_format%29">a .CUR file is just an .ICO file with extra information</a> that allows the developer to define the &#8220;host spot&#8221; position of the cursor (i.e. the part of the image which points to the position of the mouse).  Note that <strong>.CUR files support 32-bit color</strong> (16.7 million colors plus alpha channel transparency), so designers can create cursors that have semitransparent areas like shadows and anti-aliasing.   </p>
<p><strong>How does one create a .CUR file?</strong> Not too many graphic tools create .CUR files natively, but there are some easy solutions. If you are a Photoshop user, the <a href="http://www.telegraphics.com.au/svn/icoformat/trunk/dist/README.html">ICO (Windows Icon) file format plugin for Photoshop</a> is what you are looking for (I have not used it myself, but it apparently can save .CUR files directly.  Any comment on how well this works would be most welcome). If, like me, you use the GIMP, simply save the file as a .ICO file and convert it with <a href="http://www.janthor.com/sketches/index.php?/archives/10-A-Python-script-to-convert-ICO-to-CUR-files.html">this command line tool written in Python</a> by <a href="http://www.janthor.com">Jan Thor</a>. </p>
<h2>The Gotchas of Custom CSS Cursors</h2>
<p>There are a few things you need to remember when using CSS cursors</p>
<ol>
<li><strong>You must add a default &#8220;built-in&#8221; cursor after your custom cursor,</strong> or the custom cursor will not load in Firefox.  Think of it as Mozilla&#8217;s way of enforcing good web practices. :-)</li>
<li><strong>Internet Explorer interprets relative URLs as <em>relative to the HTML document</em></strong>, and not the CSS file like God (and the W3C) intended (Sometimes it seems that IE goes out of its way to make lives difficult for us developers).  This is true for all versions of IE, even IE9. To ensure cross-browser compatibility, you must either use an absolute URL:<br />
<blockquote class="code">
<pre>
#dragMe {
    cursor: url('/cursors/customMoveCursor.cur'), move;
}
</pre>
</blockquote>
<p>or a fallback url for IE:</p>
<blockquote class="code">
<pre>
/*
 * Assume this the HTML is in a directory above this CSS file
 */

#dragMe {
    cursor: url('../cursors/customMoveCursor.cur'),     /* Modern browsers    */
            url('cursors/customMoveCursor.cur'),        /* Internet Explorer  */
            move;                                       /* Older browsers     */
}
</pre>
</blockquote>
</li>
<li><strong>It is best that your .CUR files are 32&#215;32 pixels in size.</strong>  IE9 seems to resize cursors that are smaller than this to 32&#215;32, and IE8 and under cannot show cursors larger than this size.  While it is true that you can fit multiple file sizes inside a .CUR file, sticking with one 32&#215;32 image will ensure cross-browser consistency.</li>
<li>Although .CUR files can be saved in either a compressed or uncompressed format, <strong>not all browsers can read the compressed ones</strong>.  It is best to save your cursors in uncompressed format.  If you are using the GIMP to save to .ICO format first before you convert to .CUR, make sure that the .ICO is saved without compression.</li>
</ol>
<h2>Performance Issues</h2>
<p>As mentioned earlier, a lot of browsers (like Firefox or IE6) cannot show <em><strong>compressed</strong></em> .CUR files, but they can show .PNG files.  Since we would like to use a compressed version if possible, one could do this:</p>
<blockquote class="code">
<pre>
#dragMe {
    cursor: url('/cursors/customMoveCursor.png'),      /* Modern browsers    */
            url('/cursors/customMoveCursor.cur'),      /* Internet Explorer  */
            move;                                      /* Older browsers     */
}
</pre>
</blockquote>
<p><strong>This works well as long as the cursor hotspot is 0,0.</strong>  You can define a PNG hotspot using the CSS3 cursor syntax, but it breaks IE:</strong></p>
<blockquote class="code">
<pre>
#dragMe {
    cursor: url('customMoveCursor.png') 5 15, /* Modern browsers, hotspot is (5, 15)            */
            url('customMoveCursor.cur'),      /* IE chokes on the above line .. never gets here */
            move;                             /* Older browsers (IE never gets here either)     */
}
</pre>
</blockquote>
<p>In order to fix this issue, one must you conditional comments to make a separate IE from everyone else.  Let&#8217;s use a variation of <a href="http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/">Paul Irish&#8217;s Conditional Comment pattern</a> to do this.  Change the <code>html</code> tag to this:</p>
<blockquote class="code">
<pre>
&lt;!--[if (lte IE 9) ]&gt;&lt;html class="ie9 oldIE"&gt;    &lt;![endif]--&gt;
&lt;!--[if (gt IE 9)  ]&gt;&lt;html class="modern"&gt;       &lt;![endif]--&gt;
&lt;!--[!(IE)]&gt;&lt;!--&gt;    &lt;html class="notIE modern"&gt; &lt;!--&lt;![endif]--&gt;
</pre>
</blockquote>
<p>Now we can use this CSS to ensure .PNG loads in non-IE browsers:</p>
<blockquote class="code">
<pre>
html.modern #dragMe {
  cursor: url('customMoveCursor.png') 5 15, /* Modern browsers, hotspot is (5, 15).   */
          move;                             /* Older browsers                         */
}

html.oldIE #dragMe {
  cursor: url('customMoveCursor.cur'),      /* IE .CUR file loads                     */
          move;                             /* In case IE can't load the above.       */
}
</pre>
</blockquote>
<p>The extra bytes used to create the conditional comments may or may not be worth the trouble.  If you are using conditional comments (like I do all the time), it may be worth it.</p>
<h2>A Final Word On Testing in IE </h2>
<p>If you edit a .cur file on the web server and reload your page with that cursor in Internet Explorer, you may not see the edited change, since <strong>IE has kept the older cursor in cache and has a hard time letting go</strong>, kind of like <a href="http://www.youtube.com/watch?v=MBHOL1PcPR8">that person you dated in high-school</a>.  You will need to clear IE&#8217;s cache in order to see the new cursor.  This is quite annoying, and it is something you should keep in mind when troubleshooting in IE.</li>
</ul>
<h2>Further Reading</h2>
<ul>
<li><a href="http://beradrian.wordpress.com/2008/01/08/cross-browser-custom-css-cursors/">Cross-browser custom CSS cursors</a> by <a href="http://beradrian.wordpress.com/">Adrian Ber</a></li>
</ul>
<p><script type="text/javascript">
doOnLoad()
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2011/12/21/cross-browser-css-cursor-images-in-depth/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Clipping JPEG Images Into Non-Rectangular Polygons Using polyClip.js</title>
		<link>http://www.useragentman.com/blog/2011/10/29/clipping-jpeg-images-into-non-rectangular-polygons-using-polyclip-js/</link>
		<comments>http://www.useragentman.com/blog/2011/10/29/clipping-jpeg-images-into-non-rectangular-polygons-using-polyclip-js/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 15:20:29 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[canvas]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[VML]]></category>
		<category><![CDATA[arbitrary clipping]]></category>
		<category><![CDATA[clipping]]></category>
		<category><![CDATA[non-rectangular clipping. polygon clipping]]></category>
		<category><![CDATA[polyClip]]></category>
		<category><![CDATA[polygon]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=3526</guid>
		<description><![CDATA[<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/10/scissorsTeaser.jpg" /> Up until now, if a developer needed to clip an image in a non-rectangular shape, it was necessary to save the image as a PNG with an alpha channel. If the image is a photograph, the file-size balloons up to unacceptable levels. My new library, polyClip.js, allows developers to clip these images using photograph friendly JPEGs instead. This article guides you step by step on how to use it yourself.]]></description>
			<content:encoded><![CDATA[<div class="box">
<div id="explanation1">This photo is not a PNG image with an alpha channel.</div>
<div id="explanation2"><a href="http://www.useragentman.com/blog/wp-content/uploads/2011/10/scissors.jpg">It is a JPEG</a> that has been clipped with polyClip.js</div>
<div id="explanation3">
<p>The text was rotated using CSS3 Transforms, with alternate CSS for older IE using the <a href="http://www.useragentman.com/IETransformTranslator">IE Transform Translator</a>.  Original photo by <a href="http://www.flickr.com/photos/free-stock/4816852597/">Emilian Robert Vicol</a> clipped with polyClip.js</p>
</p></div>
<div class="clipParent"><img data-polyclip=" 0,0,45,3,55,8,64,18,74,24,80,32,86,45,82,32,83,38,86,46,88,52,90,62,90,68,91,76,91,82,91,83,103,87,112,91,121,97,127,102,133,106,136,112,138,116,139,121,139,122,147,125,154,127,163,129,178,131,190,132,204,132,210,131,225,124,286,107,332,96,370,88,401,83,425,79,450,76,457,77,456,80,446,85,430,91,406,99,383,108,365,114,352,119,384,117,416,116,453,114,472,113,474,113,472,118,446,126,419,132,390,138,362,144,343,148,307,153,282,157,266,159,245,160,234,160,219,160,209,163,198,167,182,175,170,183,158,194,156,195,157,201,157,204,157,204,157,210,153,219,148,229,143,236,137,244,132,250,124,258,118,263,113,267,98,276,87,281,77,283,0,284,1,191,10,190,16,191,20,191,21,192,28,191,37,190,39,189,38,190,40,190,48,190,53,191,57,191,69,188,77,187,91,183,109,179,127,173,146,166,162,158,173,153,158,151,144,150,127,151,105,152,86,154,66,157,53,160,49,161,46,165,44,167,41,168,33,168,28,167,28,166,21,170,16,171,11,171,4,170,0,168" src="http://www.useragentman.com/blog/wp-content/uploads/2011/10/scissors.jpg" alt=""  width="480" height="360" class="alignleft size-full wp-image-3771" /></div>
</div>
<p>There have been many times I have come across the need to <strong>take an image and cut an irregular shape out of it.</strong>  Normally, when a developer comes across this requirement, the only thing to do is to open the image up with your favorite graphics editor, use the select tool to cut out the shape you want, and then save the result as a <a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics">PNG</a>, since it is the only image format used by all web browsers that support alpha channels.  The problem is that <strong>PNG images, while compressed, are not as small as <a href="http://en.wikipedia.org/wiki/Jpeg">JPEGs</a> if the source image is a photograph</strong>, and the download time of a page can balloon to unacceptable levels if there are many of these types of image on a page.  When I first came across this problem, I didn&#8217;t think there was an obvious solution, but after a lot of thought, I created <strong>a library that uses <a href="http://en.wikipedia.org/wiki/HTML_canvas">HTML5 <code>canvas</code></a> to clip a JPEG </strong> (or any other image for that matter).  <strong>The library also supports older versions of IE</strong> (7-8) using the <a href="http://excanvas.sourceforge.net/">Excanvas JavaScript library</a> which polyfills <code>canvas</code> using <a href="http://en.wikipedia.org/wiki/Vector_Markup_Language">VML</a>.</p>
<h2>Okay, How Can I Do The Same Thing?</h2>
<ul>
<li><a href="https://github.com/zoltan-dulac/polyClip">Download my script from github</a> (It includes jQuery 1.6.4 and excanvas release 3.  It should work with later versions &mdash; if it doesn&#8217;t, please let me know and I&#8217;ll fix it ;-) ) .</li>
<li>Include them into the head of your document.<br />
<blockquote class="code">
<pre>
  &lt;script src="/path/to/js/jquery-1.6.2.min.js"&gt;&lt;/script&gt;

  &lt;!--[if lt IE 9 ]&gt;
   &lt;script src="/path/to/js/excanvas/excanvas.compiled.js"&gt;&lt;/script&gt;
  &lt;![endif]--&gt;

  &lt;script src="/path/to/js/polyClip-p.js"&gt;&lt;/script&gt;
</pre>
</blockquote>
</li>
<li>Layout your page as normal, placing <code>img</code> tags where you want the clipped images to go:<br />
<blockquote class="code">
<pre>
&lt;div class="clipParent"&gt;
  &lt;img src="images/image.jpg" /&gt;
&lt;/div&gt;
</pre>
</blockquote>
<p><strong>Note the <code>div</code> tag with the class of <code>clipParent</code></strong>.  You must surround all the image tags with <code>data-polyclip</code> attributes set one.  This is so you can style the image correctly, since the library will remove the image tag and replace it with a <code>canvas</code> element.
</p></blockquote>
</li>
<li>For every image on your page that you want to clip, calculate the points of the shape you want to cut out of the image and place them in the <code>data-polyclip</code> attribute.  For example, let&#8217;s say you have the following shape you want to cut out of a photograph:
<div class="centered ghost">
  <img src="/tests/polyClip/images/crop.jpg"   />
</div>
<div class="clipParent centered inFront">
  <img src="/tests/polyClip/images/crop.jpg" data-polyclip="487, 4, 500, 239, 19, 239, 43, 195" data-stroke="rgb(0, 0, 0)" /></p>
<div class="point" id="pt1" style="left: 487px; top: 4px; "><span>(487, 4)</span></div>
<div class="point" id="pt2" style="left: 500px; top: 239px"><span>(500, 239)</span></div>
<div class="point" id="pt3" style="left: 19px; top: 239px"><span>(19, 239)</span></div>
<div class="point" id="pt4" style="left: 43px; top: 195px; "><span>(43, 195)</span></div>
</div>
<p>You would then just set the <code>data-polyclip</code> attribute to those points:</p>
<blockquote class="code">
<pre>
&lt;img src="image.jpg" <span class="hilite">data-polyclip="487, 4, 500, 239, 19, 239, 43, 195"</span> /&gt;
</pre>
</blockquote>
<p>Note that the point co-ordinates are comma delimited.  If you don&#8217;t want to calculate these numbers by hand, you can use your favorite imagemap generation tool to do generate the list of coordinates.  Just remember to take the coordinates out of the imagemap code and stick it in the <code>data-polyclip</code> attribute (for the examples on this page, I used the on-line tool available at <a href="http://www.image-maps.com">image-maps.com</a>).</li>
</ul>
<h2>Why Should I Do This Instead of Using a PNG?</h2>
<p>Compare the image above with a PNG clipped with the GIMP.   Even when I compressed the PNG with <a href="http://www.useragentman.com/blog/2009/09/16/optimizing-png-files-for-both-web-and-print/">my PNG optimization script</a>, the 191K PNG file is huge compared to it&#8217;s tiny 18K polyclipped JPEG analogue (<strong>Note:</strong> file sizes refer to the size of the full image as displayed at the top of this article):</p>
<table class="dataTable">
<thead>
<tr>
<th>JPG using polyClip.js (18K)</th>
<th>PNG (191K)</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="clipParent"><img data-polyclip="0,0,55,0,64,4,70,12,80,22,82,32,86,45,82,32,83,38,86,46,88,52,90,62,90,68,91,76,91,82,91,83,103,87,112,91,121,97,127,102,133,106,136,112,138,116,139,121,139,122,147,125,154,127,163,129,178,131,190,132,204,132,210,131,225,124,286,107,332,96,370,88,401,83,425,79,450,76,457,77,456,80,446,85,430,91,406,99,383,108,365,114,352,119,384,117,416,116,453,114,472,113,474,113,472,118,446,126,419,132,390,138,362,144,343,148,307,153,282,157,266,159,245,160,234,160,219,160,209,163,198,167,182,175,170,183,158,194,156,195,157,201,157,204,157,204,157,210,153,219,148,229,143,236,137,244,132,250,124,258,118,263,113,267,98,276,87,281,77,283,0,284,1,191,10,190,16,191,20,191,21,192,28,191,37,190,39,189,38,190,40,190,48,190,53,191,57,191,69,188,77,187,91,183,109,179,127,173,146,166,162,158,173,153,158,151,144,150,127,151,105,152,86,154,66,157,53,160,49,161,46,165,44,167,41,168,33,168,28,167,28,166,21,170,16,171,11,171,4,170,0,168" src="http://www.useragentman.com/blog/wp-content/uploads/2011/10/scissors.jpg" alt=""  width="480" height="360" class="alignleft size-full wp-image-3771" /></div>
</td>
<td>
<div class="pngImage">
  <img src="http://www.useragentman.com/blog/wp-content/uploads/2011/10/scissors.png" />
  </div>
</td>
</tr>
</tbody>
</table>
<p>You may ask whether the amount of JavaScript used in this solution is greater than the bandwidth saved by using JPEG compression.  <strong>Not including jQuery, the amount of JavaScript clocks in at 2K or 13K</strong>, depending on the browser used (2K for the compressed polyClip script and 11K for excanvas, which will only be loaded by IE7-8). Although jQuery adds 91K to this equation, it doesn&#8217;t matter that much to me personally since I am probably using it for other parts of my page anyways.  <strong>Even with jQuery, the amount of JavaScript downloaded outweighs using a PNG,</strong> especially if your are clipping a larger image or a huge amount of smaller images.</p>
<p><a class="exampleLink" href="https://github.com/zoltan-dulac/polyClip">Download the latest version of polyClip.js from github.</a></p>
<h2>A Few Caveats</h2>
<ul>
<li>In IE7 and 8, the image may appear briefly as a black outline before the image appears. Other than that, it looks about the same as the other browsers.</li>
<li>The image does not show up correctly in Opera Mini.  Then again, a lot of things (e.g. CSS3 text-shadows, CSS3 Transforms, etc.) don&#8217;t show up correctly in Opera Mini. :-)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2011/10/29/clipping-jpeg-images-into-non-rectangular-polygons-using-polyclip-js/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How to Simulate CSS3 box-shadow in IE6-8 Without JavaScript.</title>
		<link>http://www.useragentman.com/blog/2011/08/24/how-to-simulate-css3-box-shadow-in-ie7-8-without-javascript/</link>
		<comments>http://www.useragentman.com/blog/2011/08/24/how-to-simulate-css3-box-shadow-in-ie7-8-without-javascript/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 04:07:03 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[box-shadow]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[IE Visual Filters]]></category>
		<category><![CDATA[Chroma]]></category>
		<category><![CDATA[DropShadow]]></category>
		<category><![CDATA[Glow]]></category>
		<category><![CDATA[IE6]]></category>
		<category><![CDATA[IE7]]></category>
		<category><![CDATA[IE8]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=3563</guid>
		<description><![CDATA[<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/intro.png" /> Using CSS3, developers can create <strong>simple</strong>, <strong>glowing</strong> and <strong>blurred</strong> box-shadows in all modern web browsers. <strong>But what about IE6-8?</strong>  This article will discuss how you can simulate them using a variety of Visual Filters to simulate them.  This article will cover a few CSS3 box-shadow effects, the equivalent Visual Filter recipes for IE 6-8, and the differences between them.]]></description>
			<content:encoded><![CDATA[<div id="intro">
<div class="box">
<span class="text">Simulating CSS3 <code>box-shadow</code> in IE6-8 <em>is</em> possible!</span>
</div>
<div class="description">The above is not an image.  It uses Allen R. Walden&#8217;s <a href="http://www.fontspace.com/allen-r-walden/neon-lights">Neon Lights</a> font and <a href="http://www.useragentman.com/blog/2010/03/09/cross-browser-css-transforms-even-in-ie/">cssSandpaper</a> to simulate CSS3 text-shadowing in IE. The box shadows are made with pure CSS in all browsers.</div>
</div>
<p><strong>CSS3 Box-Shadows are a great to quickly decorate the outside of block-level elements.</strong>  There are many CSS box-shadow recipes you can use to produce a variety of effects, including <strong>simple</strong>, <strong>glowing</strong> and <strong>blurred</strong> shadows. And, <a href="http://www.useragentman.com/blog/2011/06/29/full-css3-text-shadows-even-in-ie/">unlike CSS3 text-shadows</a>, <strong>box-shadows are natively supported by the latest version of IE.</strong>  However, if you want them to appear in <strong>older versions of IE</strong> (i.e. 6 through 8), you will want to <strong>learn how to use a variety of Visual Filters to simulate them.</strong>  This article will cover a few CSS3 box-shadow effects, the equivalent Visual Filter recipes for IE 6-8, and the differences between them. <strong>It will also cover the differences in the CSS3 implementations in all the modern browsers.</strong>  Box-shadows like the example on the left is possible in all commonly used browsers.</p>
<h2>First off, what is a <code>box-shadow</code>?</h2>
<p>A box-shadow is equivalent to a <a href="http://www.useragentman.com/blog/2011/06/29/full-css3-text-shadows-even-in-ie/">CSS3 <code>text-shadow</code></a> except it is applied to the box of the block-level element instead of the actual text.  Just like text-shadows, you can have one shadow:</p>
<blockquote class="code">
<pre>
#box {
  box-shadow: <em>&lt;x-offset&gt;</em> <em>&lt;y-offset&gt;</em> <em>&lt;blur-radius&gt;</em> <em>&lt;color&gt;</em>;
}
</pre>
</blockquote>
<p>&#8230; three shadows:</p>
<blockquote class="code">
<pre>
#box {
  box-shadow: <em>&lt;x-offset<sub>1</sub>&gt;</em> <em>&lt;y-offset<sub>1</sub>&gt;</em> <em>&lt;blur-radius<sub>1</sub>&gt;</em>, <em>&lt;color<sub>1</sub>&gt;</em>,
              <em>&lt;x-offset<sub>2</sub>&gt;</em> <em>&lt;y-offset<sub>2</sub>&gt;</em> <em>&lt;blur-radius<sub>2</sub>&gt;</em>, <em>&lt;color<sub>2</sub>&gt;</em>,
              <em>&lt;x-offset<sub>3</sub>&gt;</em> <em>&lt;y-offset<sub>3</sub>&gt;</em> <em>&lt;blur-radius<sub>3</sub>&gt;</em>, <em>&lt;color<sub>3</sub>&gt;</em>;
}
</pre>
</blockquote>
<p>&#8230; or as many as you want.  The <code>x-</code> and <code>y-offset</code>s measure the position of the horizontal and vertical shadow respectively, and the <code>blur-radius</code> measures the amount of blur in the shadow.  Let&#8217;s take a look at a simple example:</p>
<blockquote class="code">
<pre>
#box {
  <span class="hilite">box-shadow: 5px 5px 0px #ff0000;</span>
}
</pre>
</blockquote>
<table class="dataTable firstExample">
<thead>
<tr>
<th>Live HTML result</th>
<th>Firefox 4.0 Screenshot (for browsers like IE6-8<br />
that can&#8217;t see the Live result)</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div id="box0">
This is an example of a simple box-shadow without blurring
</div>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/box11.png"   />
</td>
</tr>
</tbody>
</table>
<p>Note that although <code>box-shadow</code> is the official property name, one must use the vendor-specific prefixes in order to use it in Webkit browsers (i.e. Chrome and Safari) as well as older versions of Firefox:</p>
<blockquote class="code">
<pre>
#box {
  box-shadow: 5px 5px 0px #ff0000,          /* Firefox 4.0+, Opera, IE 9 */
  -webkit-box-shadow: 5px 5px 0px #ff0000,  /* Chrome and Safari         */
  -moz-box-shadow: 5px 5px 0px #ff0000;     /* Firefox 3.6               */
}
</pre>
</blockquote>
<p>Furthermore, there are two optional parameters, the <em>spread</em> (which allows you to determine the size of the shadow) as well as the <code>inset</code> parameter that can allow you to put the shadow inside the box instead of outside of the box.  I direct readers to <a href="https://developer.mozilla.org/En/CSS/Box-shadow">Mozilla.org&#8217;s great reference for <code>box-shadow</code></a> to read more on these properties, since they are not, as far as I can tell, reproducible in IE 8 or lower. </p>
<h2>What about IE?</h2>
<p><strong>IE9 has no problem showing <code>box-shadow</code></strong> <a href="http://stackoverflow.com/questions/5617455/issue-with-box-shadow-on-ie9">except when shadowing a box within a table-cell</a> (If the CSS of the table has its <code>border-collapse</code> property set to <code>collapse</code> then the <code>box-shadow</code> is not applied.  Hopefully this is fixed in a future release). </p>
<p>As mentioned earlier, <strong>IE6-8 requires Visual Filters to simulate CSS3 box-shadows without JavaScript.</strong>  In order to illustrate this, I will show several different types of box-shadows below and show both the CSS3 syntax and the equivalent Visual Filter CSS recipe.  Some of these recipes produce almost identical results, while others are rough equivalents.  Note that all these examples use a variation of <a href="http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/">Paul Irish’s Conditional CSS Pattern</a> in order to create the IE-only rules.  This involves replacing the <code>&lt;body&gt;</code> tag of the document with this HTML:</p>
<blockquote class="code">
<pre>
   &lt;!-- Extra white-space below is just to make it easier to read. :-) --&gt;

   &lt;!--[if lt IE 7 ]&gt;   &lt;body class="ie6"&gt;          &lt;![endif]--&gt;
   &lt;!--[if IE 7 ]&gt;      &lt;body class="ie7"&gt;          &lt;![endif]--&gt;
   &lt;!--[if IE 8 ]&gt;      &lt;body class="ie8"&gt;          &lt;![endif]--&gt;
   &lt;!--[if IE 9 ]&gt;      &lt;body class="ie9"&gt;          &lt;![endif]--&gt;
   &lt;!--[if (gt IE 9) ]&gt; &lt;body class="modern"&gt;       &lt;![endif]--&gt;
   &lt;!--[!(IE)]&gt;&lt;!--&gt;    &lt;body class="notIE modern"&gt; &lt;!--&lt;![endif]--&gt;
</pre>
</blockquote>
<p>We can then apply CSS specific to a version of IE.  For example:</p>
<blockquote class="code">
<pre>
body.ie7 #box {
   /* insert IE7 specific CSS here */
}
</pre>
</blockquote>
<p>(<strong>Note:</strong> Paul Irish&#8217;s technique officially has the conditional comments around the <code>html</code> tag, not the <code>body</code> tag.  You can use either for these techniques to work.  I just prefer using the latter.)</p>
<p><strong>All these Visual Filter recipes depend on the box <a href="http://www.satzansatz.de/cssd/onhavinglayout.html">&#8220;having layout&#8221;</a>.</strong>  If you have any difficulty with the Visual Filters activating, set <code>zoom: 1</code> or a static width inside the IE6-8 specific CSS to force the block to have layout.</p>
<h3>Type #1: Simple, Unblurred Shadows</h3>
<p>In order to <strong>simulate simple, unblurred <code>box-shadow</code>s in IE</strong>, we use <a href="http://msdn.microsoft.com/en-us/library/ms532985%28v=vs.85%29.aspx">IE&#8217;s <code>DropShadow</code> Visual filter</a>: </p>
<blockquote class="code">
<pre>
#box {
  /* CSS for all browsers. */
  border: solid 1px #808080;
  background: #ffffcc;
  margin: 10px;
  padding: 10px;

  /* CSS3 Box-shadow code: */
  box-shadow: <span class="hilite">5px</span> <span class="hilite2">5px</span> 0px <span class="hilite3">#ff0000</span>;
  -webkit-box-shadow: 5px 5px 0px #ff0000;
  -moz-box-shadow: 5px 5px 0px #ff0000;
}

/* IE6-8 Specific Code */
body.ie6 #box,
body.ie7 #box,
body.ie8 #box {
   zoom: 1;
   filter: progid:DXImageTransform.Microsoft.DropShadow(<span class="hilite">OffX=5</span>, <span class="hilite2">OffY=5</span>, <span class="hilite3">Color=#ff0000</span>);
}
</pre>
</blockquote>
<table class="dataTable">
<thead>
<tr>
<th>Live HTML result</th>
<th>Firefox Screenshot</th>
<th>IE7 Screenshot</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div id="box1">
This is an example of a simple box-shadow without blurring <strong>that also works in IE6-8.</strong>
</div>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/box2Firefox.png"   />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/box2IE.png"   />
</td>
</tr>
</tbody>
</table>
<p><strong>There are two exceptions to this solution.</strong> The first deals with when the block has a <strong>transparent background</strong>, and the other has to do with <strong>negative box-shadow offsets</strong>.</p>
<h3>Type #1a: Blocks With Transparent Backgrounds</h3>
<p>Let&#8217;s say you use the above CSS, but omit the <code>background</code> property:</p>
<blockquote class="code">
<pre>
#box {
  /* CSS for all browsers.  Note there is no background-color, so box will be transparent */
  border: solid 1px #808080;
  margin: 10px;
  padding: 10px;

  /* CSS3 Box-shadow code: */
  box-shadow: 5px 5px 0px #ff0000;
  -webkit-box-shadow: 5px 5px 0px #ff0000;
  -moz-box-shadow: 5px 5px 0px #ff0000;
}

/* IE6-8 Specific Code */
body.ie6 #box,
body.ie7 #box,
body.ie8 #box {
   zoom: 1;
   filter: progid:DXImageTransform.Microsoft.DropShadow(OffX=5, OffY=5, Color=#ff0000);
}
</pre>
</blockquote>
<p>Doing this will results in some unexpected results in IE6-8:</p>
<table class="dataTable">
<thead>
<tr>
<th>Live HTML result</th>
<th>Firefox Screenshot</th>
<th>IE7 Screenshot</th>
</tr>
</thead>
<tbody>
<tr>
<td class="withGrid">
<div id="box1a">
This is an example of a box with a transparent background and simple box-shadow without blurring. IE6-8 is having a hard time dealing with the transparent background.
</div>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/box3Firefox.png"   />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/box3IE.png"   />
</td>
</tr>
</tbody>
</table>
<p>The results in IE7 are as hideous and unreadable as the average <a href="http://yourethemannowdog.ytmnd.com/">YTMND</a> page! In order to fix this issue in elderly IE, one must <strong>add a background color in IE6-8 only and remove it with the <code>Chroma</code> filter</strong> (more information on this technique can be found on my previous blog post, <a href="http://www.useragentman.com/blog/2010/09/02/how-to-make-cleartype-font-face-fonts-and-css-visual-filters-play-nicely-together/">How to Make ClearType, @font-face Fonts and CSS Visual Filters Play Nicely Together</a>).</p>
<blockquote class="code">
<pre>
#box {
  border: solid 1px #808080;
  margin: 10px;
  padding: 10px;

  /* Box-shadow code: */
  box-shadow: 5px 5px 0px #ff0000;
  -webkit-box-shadow: 5px 5px 0px #ff0000;
  -moz-box-shadow: 5px 5px 0px #ff0000;
}

body.ie6 #box,
body.ie7 #box,
body.ie8 #box {
   background-color: #ffffff;
   zoom: 1;
   filter: progid:DXImageTransform.Microsoft.DropShadow(OffX=5, OffY=5, Color=#ff0000),
           <span class="hilite">progid:DXImageTransform.Microsoft.Chroma(Color='#ffffff');</span>
}
</pre>
</blockquote>
<p>As you can see below, adding this CSS logic produces much better results:</p>
<table class="dataTable">
<thead>
<tr>
<th>Live HTML result</th>
<th>Firefox Screenshot</th>
<th>IE7 Screenshot</th>
</tr>
</thead>
<tbody>
<tr>
<td class="withGrid">
<div id="box1a-after">
This is an example of a box<br />with a transparent background and simple box-shadow<br />without blurring, with a fix for IE6-8 to deal with the transparent color.
</div>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/box4Firefox.png"   />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/box4IE.png"   />
</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> All the other types of box-shadow recipes that follow should also use this Chroma filter method when it is desirable to have a transparent background in the box itself.</p>
<h3 id="type1b" name="type1b">Type 1b: Negative Shadow Offsets</h3>
<p>If there are negative shadow offsets, you will see a small difference with the position of the box being shadowed:</p>
<blockquote class="code">
<pre>
#box {
  /* CSS for all browsers. */
  border: solid 1px #808080;
  background: #ffffcc;
  margin: 10px;
  padding: 10px;

  /* CSS3 Box-shadow code: */
  box-shadow: <span class="hilite">-10px</span> <span class="hilite2">-5px</span> 0px <span class="hilite3">#ff0000</span>;
  -webkit-box-shadow: -10px -5px 0px #ff0000;
  -moz-box-shadow: -10px -5px 0px #ff0000;
}

/* IE6-8 Specific Code */
body.ie6 #box,
body.ie7 #box,
body.ie8 #box {
   zoom: 1;
   filter: progid:DXImageTransform.Microsoft.DropShadow(<span class="hilite">OffX=-10</span>, <span class="hilite2">OffY=-5</span>, <span class="hilite3">Color=#ff0000</span>);
}
</pre>
</blockquote>
<table class="dataTable">
<thead>
<tr>
<th>Live HTML result</th>
<th>Firefox Screenshot</th>
<th>IE7 Screenshot</th>
</tr>
</thead>
<tbody>
<tr>
<td class="withGrid">
<div id="box1b">
This is an example of a simple box-shadow without blurring <strong>that also works in IE6-8.</strong>
</div>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/box1bFirefox.png"   />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/box1bIE.png"   />
</td>
</tr>
</tbody>
</table>
<p>You will note that the offsets in IE push the box down and to the right.  This is because <strong>IE&#8217;s Visual Filters believes that the box-shadow as part of the box itself,</strong> while <strong>CSS3 believes that it should be outside of the box.</strong>  As a result, negative box-shadows shift the box in IE6-8.  In order to compensate for this, one can use <code>margin-top</code> and <code>margin-bottom</code> to move the shadow to where CSS3 thinks it should be:</p>
<blockquote class="code">
<pre>
#box {
  /* CSS3 Box-shadow code: */
  box-shadow: <span class="hilite">-10px</span> <span class="hilite2">-5px</span> 0px <span class="hilite3">#ff0000</span>;
  -webkit-box-shadow: -10px -5px 0px #ff0000;
  -moz-box-shadow: -10px -5px 0px #ff0000;
}

/* IE6-8 Specific Code */
body.ie6 #box,
body.ie7 #box,
body.ie8 #box {
   zoom: 1;
   filter: progid:DXImageTransform.Microsoft.DropShadow(<span class="hilite">OffX=-10</span>, <span class="hilite2">OffY=-5</span>, <span class="hilite3">Color=#ff0000</span>);
   margin-top: <span class="hilite">10px</span>;
   margin-left: <span class="hilite2">5px</span>;
}
</pre>
</blockquote>
<table class="dataTable">
<thead>
<tr>
<th>Live HTML result</th>
<th>Firefox Screenshot</th>
<th>IE7 Screenshot</th>
</tr>
</thead>
<tbody>
<tr>
<td class="withGrid">
<div id="box1b-after">
This is an example of a simple box-shadow without blurring <strong>that also works in IE6-8.</strong>
</div>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/box1bFirefox.png"   />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/box1bIE-after.png"   />
</td>
</tr>
</tbody>
</table>
<p>Note that one could also make use relative positioning and use the CSS <code>top</code> and <code>left</code> properties to do the same thing in IE.  I leave it up to readers to decide which method would be more appropriate for the situation they find themselves in.</p>
<h3>Type #2: Glowing <code>box-shadow</code></h3>
<p>The second <code>box-shadow</code> I use a lot is what I call the &#8220;glowing box&#8221; effect.  This happens when a shadow with a large blur radius is put directly behind a box (i.e. the x- and y-offsets are set to 0, and the blur-radius is a non-zero number). It is possible to simulate this effect in IE using the <code>Shadow</code> filter. This filter must be applied four times (north, south, east and west of the box) in order to simulate the CSS3 effect.  Here is the CSS recipe:</p>
<blockquote class="code">
<pre>
#box {
   box-shadow: 0 0 5px #666666;
   -webkit-box-shadow: 0 0 5px #666666;
   -moz-box-shadow: 0 0 5px #666666;
}   

body.ie6 #box,
body.ie7 #box,
body.ie8 #box {
   zoom: 1;
   filter: progid:DXImageTransform.Microsoft.Shadow(Color=#cccccc, Strength=5, Direction=0),
         progid:DXImageTransform.Microsoft.Shadow(Color=#cccccc, Strength=5, Direction=90),
         progid:DXImageTransform.Microsoft.Shadow(Color=#cccccc, Strength=5, Direction=180),
         progid:DXImageTransform.Microsoft.Shadow(Color=#cccccc, Strength=5, Direction=270);
}
</pre>
</blockquote>
<p>&#8230; and here are the results as rendered in Firefox 4 and IE7:</p>
<table class="dataTable">
<thead>
<tr>
<th>Live HTML result</th>
<th>Firefox Screenshot</th>
<th>IE7 Screenshot</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div id="glowShadow1">
This is an example of a box that has short blurred shadows horizontally and vertically on all sides.
</div>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/blurred2Firefox.png"   />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/blurred2IE.png"   />
</td>
</tr>
</tbody>
</table>
<p>Note that the color in the Visual Filter syntax is lighter than the CSS3 one.  In order to get the equivalent IE color, I take a screenshot of the CSS3 box-shadow, open the image in The GIMP or Photoshop, and find the color that is just outside of the box.  This is the color I use in the IE syntax.  If you don&#8217;t want to go through all this trouble, you can also guess, which is what I do if I&#8217;m lazy.  Which is a lot of the time.</p>
<p>You can increase the blur radius/strength to produce larger glows as well:</p>
<blockquote class="code">
<pre>
#box {
    box-shadow: 0 0 15px #cccccc;
   -webkit-box-shadow: 0 0 15px #cccccc;
   -moz-box-shadow: 0 0 15px #cccccc;
}	

body.ie6 #box,
body.ie7 #box,
body.ie8 #box {
   zoom: 1;
   filter: progid:DXImageTransform.Microsoft.Shadow(Color=#eeeeee, Strength=15, Direction=0),
           progid:DXImageTransform.Microsoft.Shadow(Color=#eeeeee, Strength=15, Direction=90),
           progid:DXImageTransform.Microsoft.Shadow(Color=#eeeeee, Strength=15, Direction=180),
           progid:DXImageTransform.Microsoft.Shadow(Color=#eeeeee, Strength=15, Direction=270);
}
</pre>
</blockquote>
<table class="dataTable">
<thead>
<tr>
<th>Live HTML result</th>
<th>Firefox Screenshot</th>
<th>IE7 Screenshot</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div id="glowShadow2">
This is an example of a box that has longer blurred shadows horizontally and vertically on all sides.
</div>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/blurred2aFirefox.png"   />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/blurred2aIE.png"   />
</td>
</tr>
</tbody>
</table>
<p>You can also use this alternate recipe I have used one or twice if you want a darker color closer to the box, with it becoming dramatically lighter father away:</p>
<table class="dataTable">
<thead>
<tr>
<th>Live HTML result</th>
<th>Firefox Screenshot</th>
<th>IE7 Screenshot</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div id="glowShadow2a">
This is another example of a box that has longer blurred shadows horizontally and vertically on all sides.
</div>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/blurred3Firefox.png"   />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/blurred3IE.png"   />
</td>
</tr>
</tbody>
</table>
<p>Sure, the IE7 screenshot looks slightly different from the Firefox one, but <strong>let&#8217;s take a look at what all the modern browsers look with exactly the same CSS code:</strong></p>
<table class="dataTable blurredComparison">
<thead>
<tr>
<th>Opera</th>
<th>IE 9</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/blurred2aOpera.png"   />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/blurred2aIE9.png"   />
</td>
</tr>
</tbody>
<thead>
<tr>
<th>Safari 5</th>
<th>Chrome 13</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/blurred2aSafari.png"   />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/blurred2aChrome.png"   />
</td>
</tr>
</tbody>
</table>
<p>They are all slightly different.  It is almost impossible to be pixel perfect with blurred box-shadows unless you give different rules to the different browsers using vendor-specific prefixes.</p>
<p>Two important caveats about the Visual Filter rules:</p>
<ol>
<li>As mentioned before, the CSS for IE6-8 uses a lighter color for the shadow.  This is due to the way the <code>Shadow</code> filter behaves: it requires a lighter shade to simulate the same effect.</li>
<li><strong>Note that the Visual Filters examples are pushed down and to the right compared to the CSS3 example.</strong>  This is for the same reasons as stated in <a href="#type1b">Type 1b</a>, and a developer would again have to use margins or positioning to get the box in exactly the same place as it is in IE6-8:<br />
<blockquote class="code">
<pre>
#box {
   box-shadow: 0 0 5px #666666;
   -webkit-box-shadow: 0 0 5px #666666;
   -moz-box-shadow: 0 0 5px #666666;
}   

body.ie6 #box,
body.ie7 #box,
body.ie8 #box {
<span class="hilite">   margin-left: -5px;
   margin-top: -5px;</span>
   zoom: 1;
   filter: progid:DXImageTransform.Microsoft.Shadow(Color=#cccccc, Strength=5, Direction=0),
         progid:DXImageTransform.Microsoft.Shadow(Color=#cccccc, Strength=5, Direction=90),
         progid:DXImageTransform.Microsoft.Shadow(Color=#cccccc, Strength=5, Direction=180),
         progid:DXImageTransform.Microsoft.Shadow(Color=#cccccc, Strength=5, Direction=270);
}
</pre>
</blockquote>
</li>
</ol>
<h3>Type #3: Blurred <code>box-shadow</code></h3>
<p>Up until a few days ago, I thought this last type of text-shadow could not be simulated in IE using just CSS.  I then came across <a href="http://css-tricks.com/snippets/css/css-box-shadow/">an interesting recipe from CSS-Tricks</a> and <a href="http://www.der-schepp.de/blur-breaker-dropshadow/">this demo by Christian ”Schepp” Schaefer</a>. These CSS recipes came close, but was not able to control the color of the shadow itself (it assumed grey shadows only) or the exact location of the shadow.  I decided to take this work to the next level and add full control of the text-shadow, with some nice results:</p>
<table class="dataTable">
<thead>
<tr>
<th>Live HTML result</th>
<th>Firefox Screenshot</th>
<th>IE7 Screenshot</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div id="blurredShadow">
<div class="content">
                This is an example of a box with a blurred box-shadow.  It uses a special CSS recipe in order for it to work in Internet Explorer 6-8 involving a container HTML element and the Blur Visual Filter.
        </div>
</div>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/blurred4Firefox.png"   />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/blurred4IE.png"   />
</td>
</tr>
</tbody>
</table>
<p>Here is the HTML:</p>
<blockquote class="code">
<pre>
&lt;div id="box"&gt;
        &lt;div class="content"&gt;
                This is an example of a box with a blurred box-shadow.
                It uses a special CSS recipe in order for it to work in
                Internet Explorer 6-8 involving a container HTML element
                and the Blur Visual Filter.
        &lt;/div&gt;
&lt;/div&gt;
</pre>
</blockquote>
<p>and here is the CSS:</p>
<blockquote class="code">
<pre>
#box {
        /* CSS3 syntax */
	box-shadow: 5px 5px <span class="hilite2">5px</span> <span class="hilite">#cccccc</span>;
	-webkit-box-shadow: 5px 5px 5px #cccccc;
	-moz-box-shadow: 5px 5px 5px #cccccc;

        /* Place any other shared CSS properties here, except for those in the next rule */
        margin: 20px auto;
	text-align: center;
}

#box,
body.ie6 #box .content,
body.ie7 #box .content,
body.ie8 #box .content {
        /*
         * Any width, height, padding, border and background information goes here, so it is
         * shared between the CSS3 and legacy-IE solutions
         */
	width: 200px;
	padding: 10px;
	background: white;
	border: solid 1px black;
}

body.ie6 #box,
body.ie7 #box,
body.ie8 #box {
        /* This contains the color of the shadow in the CSS3 syntax */
	background: <span class="hilite">#cccccc</span>;

        /* This contains the blur-radius in the CSS3 syntax */
	zoom: 1;
	filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius=<span class="hilite2">5</span>);

        /* You must remove the border in IE, since it will be replaced in the next rule */
	border: none;
}

body.ie6 #box .content,
body.ie7 #box .content,
body.ie8 #box .content {
	position: relative;

        /*
         * Margins must be added here to place the box above the shadow correctly.
         * The margin-left and margin-right properties should be -2 times the CSS3 x-offset.
         * The margin-top and margin-bottom properties should be -2 times the CSS3 y-offset.
        /
	margin-top: -10px;
	margin-left: -10px;
	margin-bottom: -10px;
        margin-right: -10px;
}
</pre>
</blockquote>
<p>Yes, <strong>the Legacy-IE Specific CSS as long and as painful like a meeting with your accountant,</strong> but it gets the job done.  </p>
<h2>Conclusion</h2>
<p>These Visual Filters CSS recipes can come handy when you want IE6-8 to have similar box-shadow effects that modern web browsers have.  There are probably other types of box-shadows that can be handled using them, and if you are interested I encourage those with time and patience to check out Microsoft&#8217;s reference to Visual Filters and start playing with them.  Although Visual Filter support will probably be taken out of IE10, developers won&#8217;t need worry since IE9 already has box-shadow support &mdash; these experiments should only be used to add box-shadow support in older versions of IE.</p>
<h2>Further Reading</h2>
<ul>
<li><a href="https://developer.mozilla.org/En/CSS/Box-shadow">Mozilla.org&#8217;s <code>box-shadow</code> reference page</a>
<li><a href="http://css-tricks.com/snippets/css/css-box-shadow/">CSS Box Shadow</a> from <a href="http://css-tricks.com">CSS Tricks</a></li>
<li><a href="http://www.der-schepp.de/blur-breaker-dropshadow/">CSS3 Box-Shadow for Legacy IEs</a> from <a href="http://twitter.com/#!/derSchepp">Christian ”Schepp” Schaefer</a></li>
<li><a href="http://robertnyman.com/2010/03/16/drop-shadow-with-css-for-all-web-browsers/">Drop shadow with CSS for all web browsers</a> by <a href="http://robertnyman.com">Robert Nyman</a>.  Note his article includes an alternate simpler solution for a blurred <code>box-shadow</code> that involves the <code>Shadow</code> filter:<br />
<table class="dataTable">
<thead>
<tr>
<th>Live HTML result</th>
<th>Firefox Screenshot</th>
<th>IE7 Screenshot</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div id="shadow4">
                This is an example of a box with a blurred box-shadow.  It uses the <code>Shadow</code> filter for Internet Explorer 6 through 8.
</div>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/nyman1-Firefox.png"   />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/nyman1-IE.png"   />
</td>
</tr>
</tbody>
</table>
<p> but does not as similar when dealing with large shadows:</p>
<table class="dataTable">
<thead>
<tr>
<th>Live HTML result</th>
<th>Firefox Screenshot</th>
<th>IE7 Screenshot</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div id="shadow4a">
                This is an example of a box with a blurred box-shadow.  It uses the <code>Shadow</code> filter for Internet Explorer 6 through 8.
</div>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/nyman2-Firefox.png"   />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/08/nyman2-IE.png"   />
</td>
</tr>
</tbody>
</table>
<p>This difference may or may not be important to you, and again, I leave it up to the reader to decide what the right solution would be according to the situation.
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2011/08/24/how-to-simulate-css3-box-shadow-in-ie7-8-without-javascript/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Full CSS3 Text-Shadows &#8212; Even In IE</title>
		<link>http://www.useragentman.com/blog/2011/06/29/full-css3-text-shadows-even-in-ie/</link>
		<comments>http://www.useragentman.com/blog/2011/06/29/full-css3-text-shadows-even-in-ie/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 04:04:29 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[ClearType]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[IE Visual Filters]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Polyfills]]></category>
		<category><![CDATA[text-shadow]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=3296</guid>
		<description><![CDATA[<img src="/blog/wp-content/uploads/2011/06/splash.png" />While researching the possibilities of using text-shadows in IE, I noticed that there wasn't any silver bullet that produced multiple CSS3-like text-shadows in IE.  However, combining my cssSandpaper script with a refactored version of a text-shadowing script by Kazumasa Hasegawa, we can now have IE text-shadow goodness.]]></description>
			<content:encoded><![CDATA[<div id="intro" class="alignLeft">
<span id="css3And">CSS3 &amp;</span><br /><span id="html5">HTML5</span>
</div>
<p>In the last few months, <strong>I have written two articles where I discussed a few strategies to do CSS3-style transforms in IE</strong> (<a href="http://www.useragentman.com/blog/2011/04/14/css3-text-shadow-can-it-be-done-in-ie-without-javascript/">CSS3 Text-Shadow – Can It Be Done in IE Without JavaScript?</a> and <a href="http://www.useragentman.com/blog/2011/04/23/css-blurred-text-shadow-in-ie-part-i/">CSS Blurred Text-Shadow in IE — Part I</a>).  While demonstrating the possibilities to creating a varied range of text-shadows in IE, there wasn&#8217;t any silver bullet that produced what I considered one of the Holy Grails of CSS polyfills: <strong>a method that could take an existing page and render multiple CSS3 text-shadows in IE</strong> with few, if any, changes to the CSS code. To that end, at the end of my last article, I dropped the gauntlet at the end of my last article  and challenged the web development community to help come up with a better solution.  I got a few takers, but one stood out from the rest. <strong><a href="http://asamuzak.jp/">Kazumasa Hasegawa</a> submitted his script and blog post <a href="http://asamuzak.jp/html/321">(in Japanese</a> and then <a href="http://asamuzak.jp/html/322">in English</a>) about his script that could do exactly what I asked: full CSS3-style text-shadowing in IE.</strong>   It can do multiple blurred and unblurred shadows per block of text.  The only caveat is that one would have to set the CSS selectors inside a JavaScript file.  However, the code was extremely well written, and it was very easy for me to refactor it to become a plug-in for my CSS3 polyfill library, <a href="http://www.useragentman.com/blog/current-projects/cross-browser-css-transforms-even-in-ie/">cssSandpaper</a>.  Now, all a developer has to do now is include a few <code>&lt;script&gt;</code> tags into the <code>&lt;head&gt;</code>, and<strong> BAM!!! &mdash; instant text-shadow goodness in IE7+.</strong></p>
<h2>Yeah Whatever!  Show Me Proof!</h2>
<p>If you are viewing this page in IE7+, here are the droids you are looking for:</p>
<table class="dataTable">
<thead>
<tr>
<th>
Live CSS/HTML
</th>
<th class="screenshot">
IE9
</th>
<th class="screenshot">
Firefox
</th>
<th>
Text-Shadow Syntax<br />
</tr>
</thead>
<tbody>
<tr  id="example1">
<td  class="example">
<span><strong>Simple</strong></span>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie01.png" alt=""  />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff01.png" alt=""  />
</td>
<td class="code">
<pre>
2px 2px 0 #E51919
</pre>
</td>
</tr>
<tr id="example2">
<td  class="example">
<span>Blurred</span>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie02.png" alt=""  />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff02.png" alt=""  />
</td>
<td class="code">
<pre>
3px 3px 3px #B24C4C
</pre>
</td>
</tr>
<tr id="example3">
<td  class="example cssSandpaper-IEuseGradientFilter">
<span>Etched</span>
</td>
<td class="cssSandpaper-IEuseGradientFilter">
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie03.png" alt=""  />
</td>
<td class="cssSandpaper-IEuseGradientFilter">
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff03.png" alt=""  />
</td>
<td class="code">
<pre>
0px 1px 0px white
</pre>
</td>
</tr>
<tr  id="example4">
<td  class="example">
<span>Flaming</span>
</td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie04.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff04.png" alt=""  /></td>
<td class="code">
<pre>
0px   0px  4px white,    0px  -5px  4px #FFFF33,
2px -10px  6px #FFDD33, -2px -15px 11px #FF8800,
2px -25px 18px #FF2200 </pre>
</td>
</tr>
<tr  id="example5">
<td  class="example">
<span>Neon</span>
</td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie05.png" alt=""  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff05.png" alt=""  /></td>
<td class="code">
<pre>
0 0 1px  #ffffff, 0 0 2px  #ffffff,
0 0 3px  #ffffff, 0 0 4px  #ff00de,
0 0 7px  #ff00de, 0 0 8px  #ff00de,
0 0 10px #ff00de, 0 0 15px #ff00de;
</pre>
</td>
</tr>
<tr  id="example6">
<td  class="example">
<span>Unfocused</span>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie06.png" alt=""  />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff06.png" alt=""  />
</td>
<td class="code">
<pre>
0 0 3px #fff
</pre>
</td>
</tr>
<tr  id="example7" >
<td class="example">
<span>Glowing</span>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie07.png" alt=""  />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff07.png" alt=""  />
</td>
<td class="code">
<pre>
0 0 20px yellow, 0 0 60px yellow
</pre>
</td>
</tr>
<tr  id="example8">
<td  class="example">
<span>Embossed</span>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie08.png" alt=""  />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff08.png" alt=""  />
</td>
<td class="code">
<pre>
-1px -1px white, 1px 1px #333333
</pre>
</td>
</tr>
<tr  id="example9">
<td  class="example">
<span>Pillow</span>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie09.png" alt=""  />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff09.png" alt=""  />
</td>
<td class="code">
<pre>
1px 1px white, -1px -1px #444
</pre>
</td>
</tr>
<tr  id="example10">
<td  class="example">
<span>Fake 3D</span>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie10.png" alt=""  />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ff10.png" alt=""  />
</td>
<td class="code">
<pre>
1px 1px rgba(255,128,0,.7),
2px 2px rgba(255,128,0,.7),
3px 3px rgba(255,128,0,.7),
4px 4px rgba(255,128,0,.7),
5px 5px rgba(255,128,0,.7)
</pre>
</td>
</tr>
</tbody>
</table>
<p>(Note that the Blur example does not appear correctly in IE7 and 8, due to lack of support of the <code>transparent</code> color)</p>
<p>These examples were inspired by these excellent examples on the web:</p>
<ul>
<li><a href="http://www.css3.info/preview/text-shadow/">Text-shadow, Photoshop like effects using CSS</a> by <a href="http://www.css3.info">CSS3.info</a> (<a href="http://www.useragentman.com/packages/cssSandpaper-1.5/tests/csssandpaper/textshadowcss3info.html">cssSandpaper version</a>)</li>
<li><a href="http://line25.com/articles/using-css-text-shadow-to-create-cool-text-effects">Using CSS Text-Shadow to Create Cool Text Effects</a> from <a href="http://line25.com/">Chris Spooner</a> (<a href="http://www.useragentman.com/packages/cssSandpaper-1.5/tests/csssandpaper/textshadowline25.html">cssSandpaper version</a>)</li>
<li><a href="http://themegamag.com/coding/css-coding/8-css3-text-shadow-effects/">8 css3 text-shadow effects</a> by <a href="http://falemadi.com/">Fatma Alemadi</a> (<a href="http://www.useragentman.com/packages/cssSandpaper-1.5/tests/csssandpaper/textshadowthemegamag.html">cssSandpaper version</a>)</li>
</ul>
<h2>How Can cssSandpaper Give Me <code>text-shadow</code> Goodness?</h2>
<ol>
<li><a href="https://github.com/zoltan-dulac/cssSandpaperhttps://github.com/zoltan-dulac/cssSandpaper">Download the code from github</a>.</li>
<li>Include the following in the <code>head</code> of the document you have <code>text-shadow</code>ing on:<br />
<blockquote class="code">
<pre>
&lt;script type="text/javascript" src="/path/to/EventHelpers.js"&gt;
&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/textshadow.js"&gt;
&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/cssQuery-p.js"&gt;
&lt;/script&gt;
&lt;script type="text/javascript" src="/path/to/cssSandpaper.js"&gt;
&lt;/script&gt;
</pre>
</blockquote>
</li>
<li>It should now work in IE.  With the HTML5 Doctype, <a href="http://mathiasbynens.be/notes/html5-levels#level-1">you can remove the <code>type="text/javascript"</code> attributes</a>.</li>
</ol>
<p><a href="https://github.com/zoltan-dulac/cssSandpaper" class="exampleLink">Download the latest version of cssSandpaper with IE <code>text-shadow</code> support.</a></p>
<h2>Okay, What Are The Caveats</h2>
<p>Like any polyfill solution, there are a few things one has to keep in mind when using a solution like this. </p>
<ol>
<li>As you can see from the above examples, blurred text-shadows in IE look slightly different because of the different algorithm IE&#8217;s Blur Visual Filter uses compared to what CSS3 text-shadow uses.  This is not so obvious on the second example above, but becomes more obvious the more blurred text-shadows are applied on the same text.  For most applications, this is acceptable, but for those of us who like to pixel-bitch (i.e. complain when something is not pixel-perfect), you should be aware of this difference (No, I don&#8217;t know where I got that term from.  I may have made it up.  Anyone else heard of it before?)</li>
<li>Creating a large text-shadow blur (i.e. greater than 70px) on a large piece of text can cause Internet Explorer&#8217;s rendering engine to slow down when the text is scrolled into view.</li>
<li>Sometimes IE cuts off the shadows when the <code>line-height</code> is too small:<br />
<div id="attachment_3452" class="wp-caption aligncenter" style="width: 312px"><a href="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie01-cutoff.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/ie01-cutoff.png" alt="" title="ie01-cutoff" width="302" height="98" class="size-full wp-image-3452" /></a><p class="wp-caption-text">The letter 'P' and other letters with descenders may get cut off if the line-height is not set to be larger than the actual font-size.</p></div></p>
<li>In IE7-8, elements above text-shadowed text that have a <code>line-height</code> property measured in <code>em</code> units may effect the text-shadow in IE.  If there is a problem, the shadow is one pixel off from where it is supposed to be, as shown in this screenshot:<br />
<div id="attachment_3460" class="wp-caption aligncenter" style="width: 626px"><a href="http://www.useragentman.com/blog/wp-content/uploads/2011/06/1pxOff.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/1pxOff.png" alt="" title="1pxOff" width="616" height="201" class="size-full wp-image-3460" /></a><p class="wp-caption-text">Examples of a correct looking text-shadow (left) and a text shadow that is a pixel off (right).</p></div></p>
<p>As you can see from the screenshots above, this problem is much more obvious when there is no blur-radius in the text-shadow.  I am trying to see if I can work around this problem, but it looks like it has to do rounding errors when IE converts <code>em</code> units to pixels.  If you have a lot <code>em</code> units in your document, you may want to consider using <a href="/blog/2011/04/14/css3-text-shadow-can-it-be-done-in-ie-without-javascript/">my non-JavaScript solution</a> when using a single, non-blurred text-shadows.
</li>
<li>Sometimes, in order for the text-shadows to render correctly when using ClearType, you may have to use the <code>-sand-chroma-override</code> CSS property on the HTML you applied the <code>text-shadow</code> on.  This property is used by cssSandpaper to fix a problem with ClearType and IE&#8217;s Visual Filters, as described in my previous blog post, <a href="http://www.useragentman.com/blog/2010/09/02/how-to-make-cleartype-font-face-fonts-and-css-visual-filters-play-nicely-together/" >How to Make ClearType, @font-face Fonts and CSS Visual Filters Play Nicely Together</a>.  Most of the time, this property should be set to be the color that that is behind the text value of the background of the text, but sometimes you will have to look at the outline of the texts and the solid shadows to get an idea as to how it should be set.  Let&#8217;s take, for example, the &#8220;Law and Order&#8221; style text at the top of this page.  We used the following CSS to produce the text-shadow on the &#8220;CSS3&#8243; text:<br />
<blockquote class="code">
<pre>
-sand-chroma-override: #666666;
text-shadow:
	-4px 0px 0px #0f1128,
	-8px 0px 4px rgb(50, 152, 234),
	-10px 0px 4px rgba(50, 152, 234, 0.3),
	-8px -4px 4px rgba(50, 152, 234, 0.6),
	-8px 4px 4px rgba(50, 152, 234, 0.6);
</pre>
</blockquote>
<p>Why did I end up using <code>#666666</code>?  It is a greyscale color that is roughly between the brightness of the off-white text and the blue shadow.   If I set it to black instead, the outline of the text&#8217;s first dark text-shadow would be blocky, as seen here:</p>
<table class="dataTable detailedScreenshots">
<thead>
<th></th>
<th><code>-sand-chroma-override: #000000</code></th>
<th><code>-sand-chroma-override: #666666</code></th>
</thead>
<tbody>
<tr>
<th>Scale 100%</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/lawAndOrderIEChromaBlack.png" alt="" title="lawAndOrderIEChromaBlack"/></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/06/lawAndOrderIEChromaGray.png" alt="" title="lawAndOrderIEChromaBlack"/</td>
</tr>
<tr>
<th>Scale 300%</th>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/05/lawAndOrderIEChromaBlack_Detail1.png" alt="" title="lawAndOrderIEChromaBlack"/</td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/05/lawAndOrderIEChromaGray_Detail1.png" alt="" title="lawAndOrderIEChromaBlack"/</td>
</tbody>
</table>
<p>What you set this value to will depend on the text-shadow recipe you are using and, to paraphrase my Mathematics text-books in college, I leave it up to the reader to play around with the <code>-sand-chroma-override</code> value to see what looks best in which situation.
</li>
</ol>
<h2>In Conclusion</h2>
<p>This script opens up a lot of great possibilities for styling text in IE.  There is still some work to be done to make the script even better with some inevitable bugs that will need to be fixed, and I will continue to work on it to make improvements.  If you see areas for improvement, or any bugs that you see with the code, please make a comment on the <a href="https://github.com/zoltan-dulac/cssSandpaper/issues">cssSandpaper issues page on github</a>.  If you have something to contribute, I would be most grateful. :-)</p>
<p>Other changes that I am planning for cssSandpaper will include:</p>
<ol>
<li><strong>Choice of Selector Library:</strong> I will be refactoring cssSandpaper to use other selector libraries besides cssQuery, which is currently bundled with it.  <strong>This will include, but not restricted to, jQuery. </strong> This will allow developers to reduce the number of libraries included in their documents and reduce load time.</li>
<li><strong>Modularity:</strong> I will make it easy for developers to make their own plugins to support CSS properties not currently supported by cssSandpaper.  This module framework will also allow developers to only add support for the CSS properties they want to use (e.g. if a developer doesn&#8217;t use any CSS3 transforms, then they don&#8217;t have include that code or supporting libraries, like Sylvester.js).</li>
<li><strong>Only Download Code If Needed:</strong> I want to make cssSandpaper only download plugins if actually needed.  This will probably be done with Alex Sexton&#8217;s and Ralph Holzmann&#8217;s excellent <a href="http://yepnopejs.com/">yepnope.js</a> library.  While this library can be used today to speed things up, I want to look into making a little more integrated, if possible.</li>
<li><strong>Further CSS3 Support:</strong> I am looking into polyfills at the moment, like <code>border-image</code>.  Any other ideas for plugins will be most welcome.</li>
</ol>
<h2>Download cssSandpaper</h2>
<p><a href="https://github.com/zoltan-dulac/cssSandpaper" class="exampleLink">Download the latest version of cssSandpaper with IE <code>text-shadow</code> support.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2011/06/29/full-css3-text-shadows-even-in-ie/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Fixing oninput in IE Using html5Widgets</title>
		<link>http://www.useragentman.com/blog/2011/05/12/fixing-oninput-in-ie9-using-html5widgets/</link>
		<comments>http://www.useragentman.com/blog/2011/05/12/fixing-oninput-in-ie9-using-html5widgets/#comments</comments>
		<pubDate>Thu, 12 May 2011 18:43:43 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Polyfills]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[html5Widgets]]></category>
		<category><![CDATA[IE9]]></category>
		<category><![CDATA[Internet Explorer 9]]></category>
		<category><![CDATA[javascript events]]></category>
		<category><![CDATA[onforminput]]></category>
		<category><![CDATA[oninput]]></category>
		<category><![CDATA[oninput backspace]]></category>
		<category><![CDATA[oninput cut]]></category>
		<category><![CDATA[oninput delete]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=3174</guid>
		<description><![CDATA[<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/05/oninput.png" alt="" title="oninput" width="250" height="140" class="alignleft size-full wp-image-3197" /> Even though <code>onforminput</code> is deprecated, <code>oninput</code> will allow developers to do dynamic calculations on forms with little JavaScript knowledge.  Unfortunately, it doesn't work in IE8 and lower, and there are some small bugs in IE9's implementation when trying to delete characters inside a form field. So I implemented a fix for these issues with an update to my cross-browser HTML5 Forms polyfill, html5Widgets.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/05/oninput.png" alt="" title="oninput" width="250" height="140" class="alignleft size-full wp-image-3197" /> In my <a href="/blog/2011/05/10/is-onforminput-deprecated-in-html5-forms-and-why-should-i-care-anyways/#comment-12167">previous blog post</a>, I wished that the <code>onforminput</code> event was not deprecated in the HTML5 specification.  I have used this attribute in the past to show values in range elements and show calculations of values inside a form, and thought it was perfect for those who know little JavaScript to implement features like this very easily. <a href="http://www.boogdesign.com/b2evo/">Rob Crowther</a> made <a href="/blog/2011/05/10/is-onforminput-deprecated-in-html5-forms-and-why-should-i-care-anyways/#comment-12167">pointed out</a> that the <code>oninput</code> event, which has a similar function as <code>onforminput</code> the main argument behind dropping <code>onforminput</code> event.  Makes sense, and I was happy &mdash; it works in all modern web browsers, including IE.  But as you would guess, there has to be at least one problem with a cool bit of new web technology when it comes to cross-browser implementation.</p>
<h2>What are the issues?</h2>
<p>IE has three issues related to <code>oninput</code>:</p>
<ol>
<li><code>oninput</code> is not supported at all in IE8 and lower.</li>
<li>IE9 does not allow referring to form fields directly in the <code>oninput</code> expression.  For example, this code works in all browsers except IE9:<br />
<blockquote class="code">
<pre>
&lt;form name="f1" <span class="hilite">oninput="output.value = parseFloat(darkness.value);"</span>&gt;
    Darkness Level:
    &lt;input type="range" name="darkness" value="0" min="0" max="255"&gt;
    &lt;output name="output"&gt;
&lt;/form&gt;
</pre>
</blockquote>
<p>This is not so bad, since one could refactor the event code like this:</p>
<blockquote class="code">
<pre>
&lt;form name="f1"
  <span class="hilite">oninput="document.getElementById('output').innerHTML = parseFloat(darkness.value);"</span>&gt;
    Darkness Level:
    &lt;input type="range" name="darkness" value="0" min="0" max="255"&gt;
    &lt;output id="output"&gt;
&lt;/form&gt;
</pre>
</blockquote>
</li>
<li>If you use the backspace key while entering in a value, IE9 doesn&#8217;t fire the <code>oninput</code> event.  This, in my opinion, is really bad, because it does affect how the form behaves.  For example, take the following form in IE9:<br />
<form oninput="document.getElementById('tax').innerHTML = (parseFloat(amount.value) * parseFloat(price.value) * 0.15).toFixed(2); document.getElementById('total').innerHTML = (parseFloat(amount.value) * parseFloat(price.value) * 1.15).toFixed(2)">
<table class="formTable">
<tbody>
<tr>
<th>
Amount:
</th>
<td>
<input name="amount" value="1" min="1" max="100" type="number">
</td>
</tr>
<tr>
<th>
Item:
</th>
<td>
<input name="price" value="299.99" min="1" step="0.01" type="number">
</td>
</tr>
<tr>
<th>Tax:</th>
<td><output id="tax">45.00</output></td>
</tr>
<tr>
<th>Total:</th>
<td><output id="total">344.99</output>
</td>
</tr>
</tbody>
</table>
</form>
<p>As the user types in values for the amount and price into the form, the <code>oninput</code> event calculates the tax and total.  <strong>However, if the user is entering a value into, say, the price and make a mistake and press the backspace, IE9 will not update the tax and total.</strong>  Your application will give erroneous information, the user will be surprised at the total being larger than he expected, says &#8220;screw this&#8221; and leaves the application.  Your company loses the big sale, your boss fires you, and <strong>next thing you know you are on a street, or worse, coding <a href="http://drdobbs.com/architecture-and-design/210602491">COBOL</a> on a 30 year old IBM PC running MS-DOS 1.0 in some fishing tackle store.</strong>  Not pretty.</li>
</ol>
<h2>Oh The Humanity! How Can I Prevent Such a Fate?</h2>
<p>Since I hate COBOL, I decided to update my html5Widgets library to:</p>
<ol>
<li>Add support for <code>oninput</code> for browsers that don&#8217;t support it (e.g. IE7 and 8)</li>
<li>Force IE9 to fire a form&#8217;s <code>oninput</code> when the backspace and delete keys are pressed inside any of the <code>input</code> nodes.</li>
<li>Force IE9 to fire a form&#8217;s <code>oninput</code> when the <code>cut</code> event is fired on any of the <code>input</code> nodes.</li>
</ol>
<p>Using the link below, you can see an example similar to the one above using html5Widgets to fix these issues.</p>
<p><a class="exampleLink" href="/examples/html5Widgets/tests/html5Widgets/outputWithOninput.html">Let&#8217;s see html5Widgets give IE some <code>oninput</code> goodness</a></p>
<p>In order to do this, I used ideas from <a href="http://blog.danielfriesen.name">Daniel Friesen&#8217;s</a> blog post, <em><a href="http://blog.danielfriesen.name/2010/02/16/html5-browser-maze-oninput-support/">A HTML5 Browser Maze, Oninput Support</a></em> (thanks to <a href="www.paulirish.com">Paul Irish</a> for pointing me into that direction).  The result works rather well.  Note that I did not fix the IE9 &#8220;cannot use <code>.value</code>, must use <code>.innerHTML</code>&#8221; bug described earlier. It&#8217;s a little bit more verbose, but for now it&#8217;s what a developer needs to do for true cross-browser <code>oninput</code> support. I have also kept <code>onforminput</code> support in the code, just in case anyone has used it in the past (e.g. me).  To ensure the best experience, I wouldn&#8217;t use both events on the same page.  </p>
<p>Note also I did not add support for <code>oninput</code> in any element other than <code>form</code>.  I may do this after further research in the way it supported across browsers (for example, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=195696">Firefox has an issue with <code>oninput</code> being used on <code>textarea</code> elements</a>).</p>
<h2>Download</h2>
<p><a class="exampleLink" href="https://github.com/zoltan-dulac/html5Widgets">Download the latest version of html5Widgets, which includes <code>oninput</code> support, from github.</a></p>
<h2>Further Reading</h2>
<ul>
<li><a href="http://blog.danielfriesen.name">Daniel Friesen&#8217;s</a> blog post, <em><a href="http://blog.danielfriesen.name/2010/02/16/html5-browser-maze-oninput-support/">A HTML5 Browser Maze, Oninput Support</a></em>.</li>
<li><a href="http://help.dottoro.com/ljhxklln.php">oninput event | input event</a> from the <a href="http://help.dottoro.com/">Dottoro Web Reference</a></li>
<li><a href="http://mathiasbynens.be/notes/oninput">Using the oninput event with onkeydown as its fallback</a> by the ever talented <a href="http://mathiasbynens.be/">Mathias Bynens</a>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2011/05/12/fixing-oninput-in-ie9-using-html5widgets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Is onforminput Deprecated in HTML5 Forms? (And Why Should I Care Anyways?)</title>
		<link>http://www.useragentman.com/blog/2011/05/10/is-onforminput-deprecated-in-html5-forms-and-why-should-i-care-anyways/</link>
		<comments>http://www.useragentman.com/blog/2011/05/10/is-onforminput-deprecated-in-html5-forms-and-why-should-i-care-anyways/#comments</comments>
		<pubDate>Tue, 10 May 2011 19:16:01 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Polyfills]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=3065</guid>
		<description><![CDATA[<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/05/deprecated.png" alt="" title="deprecated" width="250" height="140" class="alignleft size-full wp-image-3112" /> The <code>onforminput</code> event has been stripped out of HTML5, and it makes me sad.  This article will show examples of how it works, how you can use it today in browsers that don't support it, and hopefully will also present a good case as to why it should be put back into the HTML5 specification.  Should something this useful and easy-to-use be abandoned?]]></description>
			<content:encoded><![CDATA[<div class="importantNotes">
<h3>Update:</h3>
<p><strong>Newer versions of all browsers support the <code>form</code> element&#8217;s <code>oninput</code> attribute, which replaces the functionality of <code>onforminput</code>, and as a result I wrote a related article <a href="http://www.useragentman.com/blog/2011/05/12/fixing-oninput-in-ie9-using-html5widgets/">Fixing <code>oninput</code> in IE Using html5Widgets</a>.</strong>  Thanks to <a href="http://www.boogdesign.com/b2evo/">Rob Crowther</a> for setting me straight and providing <a href="http://jsfiddle.net/robertc/YCEKQ/">a great example</a>, which <a href="http://jsfiddle.net/dYSS6/">I have forked</a> to work for IE9.  I will refactor html5Widgets to support <code>oninput</code> in IE very soon.  I will leave this article as is for the benefit of anyone who is Googling for <code>onforminput</code> and why it was deprecated.
</p>
</div>
<p><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/05/deprecated.png" alt="" title="deprecated" width="250" height="140" class="alignleft size-full wp-image-3112" /></p>
<p>I was just doing some regression testing on <a href="http://www.useragentman.com/blog/2010/07/27/cross-browser-html5-forms-using-modernizr-webforms2-and-html5widgets/">html5Widgets</a>, and noticed that the <code>onforminput</code> event wasn&#8217;t working in Firefox 4.  This didn&#8217;t make sense to me: I designed html5Widgets to detect if the <code>output</code> tag is supported, and if not, add support for it.  I believed that if a browser supported the <code>output</code> tag, it also had to support the <code>onforminput</code> event, since I assumed that this was one of the main reasons of having the <code>output</code> tag in the first place.  However, <strong>Firefox 4 supports the <code>output</code> tag, but doesn&#8217;t support <code>onforminput</code>.</strong>  After doing a bit of light research, I came across this <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=11129">this bug report</a> that seems to indicate that <code>onforminput</code> is deprecated.  This article will discuss<strong> what <code>onforminput</code> does</strong>, why it is very <strong>useful to designers are not so strong in JavaScript</strong>, how one can <strong>add support for <code>onforminput</code> to browsers that don&#8217;t</strong>, and why I really <strong>hope someone in power adds it back to the HTML5 Forms specification,</strong> or at least something very similar.</p>
<h2>Why Do I Care</h2>
<p>For those that don&#8217;t know what this is, <strong><code>onforminput</code> is an attribute</strong> that a web author can use on the <code>output</code> tag <strong>to do some calculations with the values in a form&#8217;s input fields</strong> and show that calculation to a user.  Right now, Opera is the only browser that natively supports it, but <a href="http://www.useragentman.com/blog/2010/07/27/cross-browser-html5-forms-using-modernizr-webforms2-and-html5widgets/">in an earlier post</a> I showed how one could use it with my html5Widgets polyfill library in all the other browsers.  How does it work? To illustrate a very simple use case, let&#8217;s say I have a <code>range</code> input field:</p>

<table class="dataTable">
<thead>
<tr>
<th>HTML</th>
<th>Output</th>
</tr>
</thead>
<tbody>
<tr>
<td class="withCode">
<blockquote class="code">
<pre>
&lt;form&gt;
  Darkness Level:
  &lt;input type="range" name="darkness"
         value="0" min="0" max="255" /&gt;
&lt;/form&gt;
</pre>
</blockquote>
</td>
<td>
<form>
Darkness Level: 
<input type="range" 
       name="darkness"
       value="0"
       min="0"
       max="255" />
</form>
</td>
</tr>
</tbody>
</table>
<p>(Note the <code>range</code> element is <a href="http://remysharp.com/2010/10/08/what-is-a-polyfill/">polyfilled</a> with html5Widgets if your browser doesn&#8217;t support it).</p>
<p>The <code>range</code> input type is a slider widget, and we use it here so the user can choose a number between 0 and 255.  The slider looks cool, but from a usability standpoint, there is no feedback of what value the user is sliding to.  It would make more sense to show a number next to the slider. which gives feedback to the user as to what the slider&#8217;s value is.  This is where <code>onforminput</code> comes in:</p>

<table class="dataTable">
<thead>
<tr>
<th>HTML</th>
<th>Output</th>
</tr>
</thead>
<tbody>
<tr>
<td class="withCode">
<blockquote class="code">
<pre>
&lt;form&gt;
  Darkness Level:
  &lt;input type="range"
     name="darkness"
     value="0" min="0" max="255" /&gt;
  <span class="hilite">&lt;output 
     onforminput="this.value = darkness.value"
  &gt;0&lt;/output&gt; / 255</span>
&lt;/form&gt;

</pre>
</blockquote>
</td>
<td>
<form>
  Darkness Level:
  <input type="range" name="darkness"
         value="0" min="0" max="255" />
  <output 
         onforminput="this.value = darkness.value"
  >0</output> / 255
</form>
</td>
</tr>
</tbody>
</table>
<p><strong>Immediate user feedback!  Great user experience! <em>And simple syntax!</em></strong>  Even a person who is not familiar with JavaScript can figure it out.  But it&#8217;s deprecated!  So, even though the <code>output</code> tag is supported by Firefox 4, <code>onforminput</code> is not.  Oh-noes!!!!</p>
<p>Luckily, my html5Widgets library adds support for it in browsers that don&#8217;t, including Firefox 4.  I just made a small change that worked around an issue preventing Firefox from supporting it, and BAM!  Instant support.</p>
<p>Another good (and common) example for using <code>output</code> would be a form for an online tool that calculates a total automatically.  Enter in values into the following form and see the calculations magically appear:</p>

<form>
<table class="formTable">
<tbody>
<tr>
<th>
Amount:
</th>
<td>
<input type="number" name="amount" value="1" min="1" max="100" />
</td>
</tr>
<tr>
<th>
Item:
</th>
<td>
<input type="number" name="price" value="299.99" min="1" step="0.01" />
</td>
</tr>
<tr>
<th>Tax:</th>
<td><output onforminput="this.value = (parseFloat(amount.value) * parseFloat(price.value) * 0.15).toFixed(2)"
>0</output></td>
</tr>
<tr>
<th>Total:</th>
<td><output onforminput="this.value = (parseFloat(amount.value) * parseFloat(price.value) * 1.15).toFixed(2)"
>0</output>
</tr>
</tbody>
</table>
</form>
<h2>But, why is it depreciated in the first place?</h2>
<p>It seems the decision has been made to remove <code>onforminput</code> from the HTML5 specification since it&#8217;s purpose can be easily done with capturing events (at least, that&#8217;s what I understood from <a href="http://lists.w3.org/Archives/Public/public-webapps/2010OctDec/0177.html">this thread about <code>onforminput</code> and <code>onformchange</code> on the public-webapps mailing list</a>).  </p>
<p>While this is true, I think keeping it in would be a huge help to designers and developers.  I even think that having it declared inline like I do in the code examples above is useful.  Even though it breaks the separation of document structure and behavior, it allows a developer with practically no JavaScript knowledge to implement this simple feature in a form.  According to the <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=11129">Bug Report</a>, designers shouldn&#8217;t have to use <code>onforminput</code> since they can do this instead: </p>
<blockquote class="code">
<pre>
&lt;form name="f1"&gt;
Darkness Level:
<div class="hilite">    &lt;script type="text/javascript"&gt;
      document.addEventListener("input",
        function(e) {
          if (document.forms.f1 == e.target.form)
            e.target.form.output.value =
              parseFloat(e.target.form.darkness.value);
        }, true);
    &lt;/script&gt;</div>

    &lt;input type="range" name="darkness"
         value="0" min="0" max="255" /&gt;
    &lt;output name="output"&gt;
  &lt;/form&gt;
</pre>
</blockquote>
<p><strong>This is uglier than your Mom&#8217;s mood when you don&#8217;t call her on Mother&#8217;s Day</strong> (not that I&#8217;m speaking from any recent experience). Even though it is dead easy for a JavaScript programmer to implement this without <code>onforminput</code>, some web designers wouldn&#8217;t have the knowledge or the patience to do so.  This is not a slight to those designers &mdash; after all, they can probably make better looking web pages than the average programmer. So I am keeping <code>onforminput</code> in html5Widgets.  It is really convenient and easy to understand.</p>
<h2>A Note To Those In Power</h2>
<p><strike>To anyone at the W3C who has the power to do so, I am politely asking to reconsider and <strong>please put <code>onforminput</code> back into the specification</strong> or <strong>at least replace it with something just as simple</strong> (the latter being attractive to those who want to continue separating the structure of the document (i.e. HTML) from the behavior (i.e. JavaScript)).</strike> As mention in the update on the top of the page, <code>oninput</code> is a great replacement for <code>onforminput</code> and it works in all modern browsers.  </p>
<p>In my humble opinion, creating calculations the old-fashioned way with events and lines and lines of JavaScript is painful for designers who aren&#8217;t scripters.  After all, isn&#8217;t this the reason why <code>required</code> and <code>pattern</code> were created?</p>
<p><a class="exampleLink" href="https://github.com/zoltan-dulac/html5Widgets">Download the latest version of html5Widgets, which includes <code>onforminput</code> support, from github</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2011/05/10/is-onforminput-deprecated-in-html5-forms-and-why-should-i-care-anyways/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>CSS Blurred Text-Shadow in IE &#8212; Part I</title>
		<link>http://www.useragentman.com/blog/2011/04/23/css-blurred-text-shadow-in-ie-part-i/</link>
		<comments>http://www.useragentman.com/blog/2011/04/23/css-blurred-text-shadow-in-ie-part-i/#comments</comments>
		<pubDate>Sun, 24 Apr 2011 03:26:16 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[CSS3]]></category>
		<category><![CDATA[IE Visual Filters]]></category>
		<category><![CDATA[text-shadow]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[blurred text-shadow]]></category>
		<category><![CDATA[Cross-Browser CSS3 text-shadow]]></category>
		<category><![CDATA[Cross-Browser text-shadow]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3 blurred text-shadow]]></category>
		<category><![CDATA[CSS3 text-shadow]]></category>
		<category><![CDATA[DropShadow]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[ie filters]]></category>
		<category><![CDATA[IE9]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[Visual Filters]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=2946</guid>
		<description><![CDATA[<img src="/blog/wp-content/uploads/2011/04/introIE9.png" /> Last week, I discussed several strategies web developers can use to simulate CSS text-shadow in IE.  <a href="http://www.useragentman.com/blog/2011/04/14/css3-text-shadow-can-it-be-done-in-ie-without-javascript/">In that article</a>, I mentioned that there was no way that I knew of to simulate text-shadow with a blur-radius in IE without JavaScript.  Since then, <strong>I have discovered a way to simulate the CSS <code>text-shadow</code> effect in IE9 that does not use JavaScript and does not add extra elements to the DOM.</strong>]]></description>
			<content:encoded><![CDATA[<div class="importantNotes">
<h3>Notes:</h3>
<ul>
<li>Before reading this article, you may want to read <a href="http://www.useragentman.com/blog/2011/04/14/css3-text-shadow-can-it-be-done-in-ie-without-javascript/">my previous article</a>, which covers producing other text-shadow effects in IE.</li>
<li>After reading this article, you may want to read <a href="http://www.useragentman.com/blog/2011/06/29/full-css3-text-shadows-even-in-ie/">my subsequent article</a>, which covers using <a href="http://www.useragentman.com/blog/csssandpaper-a-css3-javascript-library/">my cssSandpaper JavaScript library</a> <strong>to produce multiple blurred and un-blurred text-shadows in IE7+</strong></li>
<li>When I first posted this article, I wrote that this solution works with IE8 as well as IE9.  However, further testing has shown that IE8 produces unpredictable results.  Please see the <a href="#caveats">Caveats section</a> for more information</li>
</ul>
</div>
<div id="intro" class="alignLeft">
<p data-innertext="Blurred Text-Shadow in IE9 Without JavaScript">
     Blurred Text-Shadow in IE9 Without JavaScript</p>
</div>
<p>Last week, I discussed several strategies web developers can use to simulate CSS text-shadow in IE.  <a href="http://www.useragentman.com/blog/2011/04/14/css3-text-shadow-can-it-be-done-in-ie-without-javascript/">In that article</a>, I mentioned that there was no way that I knew of to simulate text-shadow with a blur-radius in IE without JavaScript.  Since then, <strong>I have discovered a way to simulate the CSS <code>text-shadow</code> effect in IE9 that does not use JavaScript and does not add extra elements to the DOM.</strong> There are some other caveats to this solution, and because of this, I have titled this article &#8220;Part 1&#8243;, since I believe more work can be done in this area to improve support for blurred text-shadows in IE.</p>
<h2>Step by Step Text-Shadowing in IE9</h2>
<p>This solution makes use of <a href="http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/">Paul Irish’s Conditional CSS Pattern</a>, and I would suggest reading that article first before proceeding any further.  I would also recommend reading my previous article, <em><a href="http://www.useragentman.com/blog/2011/04/14/css3-text-shadow-can-it-be-done-in-ie-without-javascript/">CSS3 Text-Shadow – Can It Be Done in IE Without JavaScript?</a></em>, since this solution relies on some ideas presented in that article.</p>
<p>After you become familiar with the above two articles, implementing text-shadow in IE9 becomes a two-step process.</p>
<p>For this tutorial, let&#8217;s assume the following HTML:</p>
<blockquote class="code">
<pre>
&lt;div id="intro" class="alignLeft"&gt;
  &lt;p data-innertext="Blurred Text-Shadow in IE9 Without JavaScript"&gt;
    Blurred Text-Shadow in IE9 Without JavaScript
  &lt;/p&gt;
&lt;/div&gt;
</pre>
</blockquote>
<p>(Note the <code>data-innertext</code> attribute in the element we want to add the text-shadow to.  This must contain exactly the same text that the element itself contains. We&#8217;ll explain why we need this later on).</p>
<p>Let&#8217;s also assume we want a gray text-shadow with both an x- and y-offset of 3 pixels as well as a blur radius of 3 pixels:</p>
<blockquote class="code">
<pre>
#intro p {
     text-shadow: <span class="hilite">3px 3px</span> <span class="hilite2">3px</span> <span class="hilite3">#cccccc</span>;
     width: 230px;
}
</pre>
</blockquote>
<p>Let&#8217;s look at the result so far:</p>
<table class="dataTable">
<thead>
<tr>
<th>Firefox screenshot</th>
<th>IE screenshot</th>
</tr>
</thead>
<tbody>
<tr>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/firefox-all.png" alt="Firefox screenshot" title="Firefox screenshot"  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/ie-1.png" alt="IE screenshot without blurred text-shadow" title="IE screenshot without blurred text-shadow"  /></td>
</tr>
</tbody>
</table>
<p>As one would expect, works in Firefox but not in IE9.</p>
<p><a class="exampleLink" href="/tests/textShadow/blur1.html">See the above <code>text-shadow</code> code in action (without any IE9 goodness)</a></p>
<h3>Step 1 &#8211; IE Blur Filter</h3>
<p>Using <a href="http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/">Paul Irish’s Conditional CSS Pattern</a>, we make an IE9 only rule that will blur the text</p>
<blockquote class="code">
<pre>
#intro p {
     text-shadow: 3px 3px <span class="hilite2">3px</span> <span class="hilite3">#cccccc</span>;
     width: 230px;
}

/* Step 1: apply the Chroma and Blur filter to the text you want the Drop Shadow on */
body.ie9 #intro p {
	zoom: 1;
	color: <span class="hilite3">#cccccc</span>;
	background-color: <span class="hilite">#ccccce</span>;
	filter: progid:DXImageTransform.Microsoft.Chroma(color=<span class="hilite">#ccccce</span>),
	        progid:DXImageTransform.Microsoft.Blur(<span class="hilite2">pixelradius=3</span>);
}
</pre>
</blockquote>
<p>Note four things:</p>
<ol>
<li>I set the <code>color</code> to be the color of the text-shadow.</li>
<li>We set a background-color to be halfway between the color of the text (black) and the visual background of the text (white).  In this case, I chose <code>#ccccce</code> since <code>#cccccc</code> is already being used by as the color of the text-shadow.</li>
<li>We remove the background color with the <a href="http://msdn.microsoft.com/en-us/library/ms532982%28v=vs.85%29.aspx"><code>Chroma</code> Visual Filter</a> (this is necessary to avoid the Blur filter from being pixelated, in the same manner as <a href="/blog/2011/04/14/css3-text-shadow-can-it-be-done-in-ie-without-javascript/">the text-shadows in my previous article</a>).</li>
<li>We apply the <a href="http://msdn.microsoft.com/en-us/library/ms532979%28v=vs.85%29.aspx"><code>Blur</code> Visual Filter</a> to have a <code>pixelradius</code> of 3 (which is the same as the blur radius from the <code>text-shadow</code>.</li>
</ol>
<table class="dataTable">
<thead>
<tr>
<th>Firefox screenshot</th>
<th>IE screenshot</th>
</tr>
</thead>
<tbody>
<tr>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/firefox-all.png" alt="Firefox screenshot" title="Firefox screenshot"  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/ie-2.png" alt="IE screenshot of text with Chroma and Blur filters applied" title="IE screenshot of text with Chroma and Blur filters applied"  /></td>
</tr>
</tbody>
</table>
<p><a class="exampleLink" href="/tests/textShadow/blur2.html">See the above code in action (IE9 will only show the blurred text)</a></p>
<p>So now we have the shadow in IE!  But what about the solid text on top?</p>
<h3>Step 2 &#8211; Use <code>:before</code> To Replace the Solid Text</h3>
<p>We now must add one more selector in order to get our black, un-blurred text back:</p>
<blockquote class="code">
<pre>
/* Step 2: create a :before rule on the blurred text */
body.ie9 #intro p:before {
  /* color and width of the original text */
  color: black;
  width: 230px;

  /* This is needed to place the text directly over the shadow. */
  position: absolute;

  /* This assumes that the data-innertext is the same as the text inside the element. */
  content: attr(data-innertext);

  /* Positions the text */
  margin-top: 0px;
  margin-left: 0px;
}
</pre>
</blockquote>
<p>The <code>:before</code> rule duplicates the blurred text, colors it black and places it before the blurred text.  The text is then duplicated because of the <code>content</code> property, which uses the value of the <code>data-innertext</code> attribute as the generated content &mdash; now you know why we set <code>data-innertext</code> at the beginning of this example.  It is absolutely positioned, and since the <code>top</code> and <code>left</code> properties are not set, it places the text on top of the original text.  Also note that the <code>width</code> is the same as the original element (in this case <code>230px</code>).  This is very important, otherwise the shadow will not appear below the text correctly. </p>
<p>The only thing left to explain is the margins and how they position the text.  We must use these formulas to produce the x- and y- offsets of the original <code>text-shadow</code></p>
<div class="equation">
<p><code>margin-left</code> = blur-radius &#8211; offset-x </p>
<p><code>margin-top</code> = blur-radius &#8211; offset-y </p>
</div>
<p>Why do we need to do this?  Because adding the <code>Blur</code> filter pushes the text a few pixels from down and to the right &mdash; namely, the same amount of pixels from the blur-radius.  These simple formulas compensate for that, and place the shadows according to what you set for the x- and y-offsets.</p>
<table class="dataTable">
<thead>
<tr>
<th>Firefox screenshot</th>
<th>IE screenshot</th>
</tr>
</thead>
<tbody>
<tr>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/firefox-all.png" alt="Firefox screenshot" title="Firefox screenshot"  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/ie-3.png" alt="IE screenshot of simultaed text-shadow" title="IE screenshot of simultaed text-shadow"  /></td>
</tr>
</tbody>
</table>
<p>And now, let&#8217;s take a look at the difference close up:</p>
<table class="dataTable">
<thead>
<tr>
<th>Firefox screenshot</th>
<th>IE screenshot</th>
</tr>
</thead>
<tbody>
<tr>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/firefox-zoom.png" alt="Firefox screenshot" title="Firefox screenshot"  /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/ie-zoom.png" alt="IE screenshot of simultaed text-shadow" title="IE screenshot of simultaed text-shadow"  /></td>
</tr>
</tbody>
</table>
<p>Note: the other browsers look about the same in Firefox, so I didn&#8217;t bother posting screen captures of them.</p>
<p><a class="exampleLink" href="/tests/textShadow/blur3.html">See the above code in action, with IE9&#8242;s blurred <code>text-shadow</code> workaround.</a></p>
<h2 id="caveats" name="caveats">Caveats</h2>
<p>This solution only works under certain conditions:</p>
<ol>
<li><strong>You cannot have more than one type of font, font-size, font-weight or font-style with the shadowed element.</strong>  This is due to the way we produce the shadow (i.e. the <code>data-innertext</code> cannot contain any HTML elements to control the style).</li>
<li><strong>The shadowed element cannot be an <code>inline</code> element.</strong>  It can be a block or an inline-block though.</li>
<li><strong>Any background colors or background-images that you want to appear in with the text-shadow must appear in an outside element.</strong>  For example, in the following HTML, you would put the <code>background-image</code> or <code>background-color</code> on the <code>&lt;div&gt;</code> tag, not the <code>&lt;p&gt;</code> tag which would have the <code>text-shadow</code>.<br />
<blockquote class="code">
<pre>
&lt;div id="intro" class="alignLeft"&gt;
  &lt;p data-innertext="Blurred Text-Shadow in IE9 Without JavaScript"&gt;
    Blurred Text-Shadow in IE9 Without JavaScript
  &lt;/p&gt;
&lt;/div&gt;
</pre>
</blockquote>
</li>
<li><strong>The shadowed element must be of fixed width</strong> (i.e. widths can be measured in <code>px</code>, <code>em</code>, etc.  <strong>Percentages will not work</strong>).</li>
<li><strong>As far as I know, it is impossible to have multiple text-shadows on the same block of text.</strong>  If you wish to do this do glow text, you may want to look at my previous article, <em><a href="/blog/2011/04/14/css3-text-shadow-can-it-be-done-in-ie-without-javascript" />CSS3 Text-Shadow – Can It Be Done in IE Without JavaScript?</a></em>.
<li><strong>It only works in IE9.</strong>  When I originally posted this article, I claimed it worked with IE8, but after further testing, when setting a font on a <code>:before</code> rule, IE8 sometimes produces unpredictable results (sometimes, the font is set to something different than the original text, and other times, the letter spacing is not correct).  IE8 and lower are out of luck. :-(</li>
</ol>
<h2>An Open Challenge To Improve This Technique</h2>
<p>Think you can do better?  I challenge you!  I am almost certain there has to be a better way with fewer restrictions that the solution I give here. I also know there are quite a few smart people out there who read this blog, so <strong>I am dropping the gauntlet and challenging everyone reading this article to help come up with a better solution.</strong>  Post a URL with an example below, and if I like what I see, I will post a follow up article to this one with what I believe are the best solutions. Here&#8217;s your chance to solve what I think is a huge web development problem and be recognized as Someone Really Clever&trade;.</p>
<p>Unless, of course, I come up with a better solution first. :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2011/04/23/css-blurred-text-shadow-in-ie-part-i/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

