<?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 &#187; Technologies</title>
	<atom:link href="http://www.useragentman.com/blog/category/technologies/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>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>
		<item>
		<title>CSS3 Text-Shadow &#8211; Can It Be Done in IE Without JavaScript?</title>
		<link>http://www.useragentman.com/blog/2011/04/14/css3-text-shadow-can-it-be-done-in-ie-without-javascript/</link>
		<comments>http://www.useragentman.com/blog/2011/04/14/css3-text-shadow-can-it-be-done-in-ie-without-javascript/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 14:13:05 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[ClearType]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[IE Visual Filters]]></category>
		<category><![CDATA[text-shadow]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Cross-Browser CSS3 text-shadow]]></category>
		<category><![CDATA[Cross-Browser text-shadow]]></category>
		<category><![CDATA[CSS]]></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=2720</guid>
		<description><![CDATA[<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/splash.png" /> CSS3 <code>text-shadow</code> rocks, but it doesn't work in any version of Internet Explorer, including IE9.  While it is impossible to replicate all <code>text-shadow</code> effects in The Browser That Likes To Be Difficult, there are some ways to emulate this effect without JavaScript using Visual Filters, even when ClearType is enabled.  This article can show you how and contains lots of examples.]]></description>
			<content:encoded><![CDATA[<div class="importantNotes">
<h3>Update: April 24, 2011</h3>
<p>Since writing this article, I have also discovered <a href="http://www.useragentman.com/blog/2011/04/23/css-blurred-text-shadow-in-ie-part-i/">a way to implement blurred text-shadows in IE8+</a>.
</div>
<div class="importantNotes">
<h3>Update: July 13, 2011</h3>
<p>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 <strong>using my cssSandpaper JavaScript library to produce multiple blurred and un-blurred text-shadows in IE7+.</strong></p>
</div>
<div id="introExample" class="alignLeft">
<p>CSS3 + IE</p>
</div>
<p>When IE9 was released, I was really happy to see all the great CSS3 features it supported.  2D Transforms, advanced selectors, border-radius, rgba/hsla colors, WOFF fonts &#8230; the list goes on.  And no polyfills required!  <strong>I was, however, disappointed that IE9 doesn&#8217;t support two of my favorite CSS3 effects: <code>border-image</code> and <code>text-shadow</code>.</strong>  I&#8217;m sure that I will notice other CSS3 effects missing over time, but these are two features that I currently find incredibly useful. This article will deal with <code>text-shadow</code>: how it works in browsers that support it, and strategies we can use today to emulate some of its functionality in IE.  <strong>Although the solutions I present here are based on IE&#8217;s Visual Filters,</strong> and that some articles like <a href="http://www.workingwith.me.uk/articles/css/cross-browser-drop-shadows">this one by Neil Crosby</a> have looked into it as a solution, <strong>I present here some new information</strong> &#8211; how to make them work correctly with Windows Standard and ClearType font-smoothing and how to write the final CSS that won&#8217;t break any browser.</p>
<h2>How does CSS3 <code>text-shadow</code> Work?</h2>
<p>Before we go on about IE, let&#8217;s have a quick overview of how the CSS3 specification works.  In all the other browsers (i.e. Firefox 3.0+, Safari 4.0+, Opera 10.0+ and Chrome 4.0+) text-shadow has pretty solid support.  Its basic syntax is:</p>
<blockquote class="code">
<pre>
#obj {
   text-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>The <em>x-offset</em> and <em>y-offset</em> state how many pixels horizontally and vertically the shadow is positioned with respect to the original text, while the <em>blur-radius</em> is used to express how much the shadow is blurred (the higher the value, the more blurry it is).  All of these values can be expressed using any CSS unit of measure (e.g. <code>px</code>, <code>em</code>, etc).  The <em>color</em> can be any CSS color value, representing the color of the text.</p>
<p>Here are some examples:</p>
<table class="dataTable screenshots">
<thead>
<tr>
<th>Pure CSS Example (will be visible if your browser supports <code>text-shadow</code></th>
<th>Firefox Screenshot (similar in other browsers except IE)</th>
</tr>
</thead>
<tbody>
<tr>
<td id="cssExample1" class="test">text:shadow: 5px 5px 0px black;</td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/example1.png" alt="Screenshot of the text on the left in Firefox." /></td>
</tr>
<tr>
<td id="cssExample2" class="test">text:shadow: 5px 5px 5px black;</td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/example2.png" alt="Screenshot of the text on the left in Firefox." /></td>
</tr>
<tr>
<td id="cssExample3" class="test">text:shadow: 1px 0px 0px white;</td>
<td class="example3"><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/example3.png" alt="Screenshot of the text on the left in Firefox." /></td>
</tr>
</tbody>
</table>
<p>You are not restricted to just one shadow.  You can have multiple shadows, separated by commas.  For example:</p>
<blockquote class="code">
<pre>
#obj {
	text-shadow:
		 1px -1px 5px rgba(0, 0, 0, 0.2),
		-1px  1px 5px rgba(0, 0, 0, 0.2),
		 1px  1px 5px rgba(0, 0, 0, 0.2),
		-1px -1px 5px rgba(0, 0, 0, 0.2),
		 0px  1px 5px rgba(0, 0, 0, 0.2),
		 0px -1px 5px rgba(0, 0, 0, 0.2),
		 1px  0px 5px rgba(0, 0, 0, 0.2),
		-1px  0px 5px rgba(0, 0, 0, 0.2);
}
</pre>
</blockquote>
<p>renders white text legibly on a white background:</p>
<table class="dataTable screenshots">
<thead>
<tr>
<th>Pure CSS Example (will be visible if your browser supports <code>text-shadow</code></th>
<th>Firefox Screenshot (similar in other browsers except IE)</th>
</tr>
</thead>
<tbody>
<tr>
<td id="white" class="test">
This is white text on a white background
</td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/example4.png" alt="Screenshot of the text on the left in Firefox." /></td>
</tr>
<tr>
</tbody>
</table>
<h2>Well &#8230; What About IE?</h2>
<p><strong>Currently, no version of Internet Explorer natively understands the CSS3 Syntax for <code>text-shadow</code>. </strong> However, IE 4.0+ can do text-shadow-like effects using Microsoft&#8217;s proprietary <a href="http://msdn.microsoft.com/en-us/library/ms532853%28v=vs.85%29.aspx">Visual Filters</a> &#8212; unfortunately, if the user&#8217;s computer has any type of font-smoothing technology enabled, the <strong><a href="http://msdn.microsoft.com/en-us/library/ms532985%28v=vs.85%29.aspx"><code>DropShadow</code></a> Visual Filter effect is quite messy and ugly</strong>.  Since <a href="http://blogs.msdn.com/b/e7/archive/2009/06/23/engineering-changes-to-cleartype-in-windows-7.aspx">ClearType is enabled by default</a> in modern versions of the Windows operating system (i.e. Vista, Windows 7) and is <a href="http://social.technet.microsoft.com/Forums/en/ieitprocurrentver/thread/01c447b1-5c78-4d2f-9968-6eeabc04a68b">very difficult to disable it in Internet Explorer 9</a>, this is a show-stopper. <strong>Don&#8217;t dispair, there is a workaround.</strong> Let&#8217;s see how <code>DropShadow</code> is supposed to work, and see how <strong>we can &#8220;clean-up&#8221; the result to look much nicer in modern versions of Windows.</strong></p>
<h3>Basic Text-Shadow</h3>
<p>Let&#8217;s first take a look at a basic text-shadow without any blurring of the shadow:</p>
<blockquote class="code">
<pre>
#basicTextShadow {
	background-color: white;
}

#basicTextShadow p {
	text-shadow: <span class="hilite2">3px 3px</span> 0px <span class="hilite3">#99cc99</span>;
}
</pre>
</blockquote>
<p>The equivalent Visual Filter syntax is:</p>
<blockquote class="code">
<pre>

#basicTextShadow {
	background-color: white;
}

#basicTextShadow p {
	zoom: 1;
	filter: progid:DXImageTransform.Microsoft.DropShadow(<span class="hilite2">OffX=3, OffY=3</span>, <span class="hilite3">Color=#99cc99</span>);
}
</pre>
</blockquote>
<p>Note that the <code>zoom</code> line &mdash; it is here since it <a href="http://www.satzansatz.de/cssd/onhavinglayout.html">forces IE to recognize that the object &#8220;has layout&#8221;</a>.  Visual Filters do not work unless a node &#8220;has layout&#8221;.</p>
<p>The problem is that when ClearType is turned on, many Visual Filters, including <code>DropShadow</code> don&#8217;t render text very well:</p>
<table class="dataTable  screenshots">
<thead>
<tr>
<th>IE <code>DropShadow</code> without ClearType</code></th>
<th>IE <code>DropShadow</code> with ClearType</th>
</tr>
</thead>
<tbody>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/justDropShadowWithoutFontSmoothing.png" alt="IE DropShadow without ClearType" />
</td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/justDropShadowWithFontSmoothing.png" alt="IE DropShadow with ClearType" />
</td>
</tbody>
</table>
<p>The text renders much better when you have a <code>background-color</code>.  </p>
<blockquote class="code">
<pre>
#basicTextShadow p {
	zoom: 1;
	<span class="hilite">background-color: white;</span>
	filter: progid:DXImageTransform.Microsoft.DropShadow(OffX=3, OffY=3, Color=#99cc99);
}
</pre>
</blockquote>
<p><div id="attachment_2882" class="wp-caption aligncenter" style="width: 335px"><a href="http://www.useragentman.com/blog/wp-content/uploads/2011/04/dropShadowWithBackground.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/dropShadowWithBackground.png" alt=" IE using the DropShadow Visual Filter with a &lt;code&gt;background-color&lt;/code&gt;." title="dropShadowWithBackground" width="325" height="130" class="size-full wp-image-2882" /></a><p class="wp-caption-text"> IE using the <code>DropShadow</code> Visual Filter with a <code>background-color</code>.</p></div></p>
<p>However, this will cause <code>DropShadow</code> to behave more like the CSS3 <code>box-shadow</code> property.</p>
<p>How can we have the font render well <em>without</em> the <code>background-color</code>.  All we have to do is cut-out the background-color using the <a href="http://msdn.microsoft.com/en-us/library/ms532982%28v=vs.85%29.aspx"><code>Chroma</code> filter</a>:</p>
<blockquote class="code">
<pre>
#basicTextShadow p {
	zoom: 1;
	background-color: <span class="hilite">white</span>;
	filter: progid:DXImageTransform.Microsoft.Chroma(Color=<span class="hilite">white</span>)
		progid:DXImageTransform.Microsoft.DropShadow(OffX=3, OffY=3, Color=#99cc99);
}
</pre>
</blockquote>
<table class="dataTable">
<thead>
<tr>
<th>Firefox using CSS3 <code>text-shadow</code></th>
<th>IE with <code>Chroma</code> and <code>DropShadow</code> Filters Applied</th>
</tr>
</thead>
<tbody>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/firefoxBasic.png" alt="Firefox Using CSS3 Syntax." />
</td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/dropShadowWithBackgroundAndChroma.png" alt="IE with Chroma and DropShadow Filters Applied" />
</td>
</tbody>
</table>
<p><strong>The Chroma filter allows us to remove a specific color from the rendered element.</strong>  In this case, we are removing white, which is also the background-color.  As a result the font renders smoothly, and the <code>DropShadow</code> filter behaves almost like a true <code>text-shadow</code>.  This is similar to the method I describe in a previous article I wrote, <a href="http://www.useragentman.com/blog/2010/09/02/how-to-make-cleartype-font-face-fonts-and-css-visual-filters-play-nicely-together/" rel="bookmark" title="Permanent Link to 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>.  To sum-up: regardless of whether you use @font-face or not, you can make Visual Filters render text correctly by creating a background for the element, and then removing that background with the <code>Chroma</code> filter.</p>
<p><a class="exampleLink" href="http://www.useragentman.com/tests/textShadow/example1.html">See the above three examples in action (IE is recommended in order to see the Visual Filter differences)</a></p>
<p>Here is some actual HTML that is styled so that all browsers, including IE, will render a text-shadow correctly:</p>
<div id="basicTextShadow" class="test">
<p>This is an example of a basic text-shadow.  Note that is looks almost the same in browsers that understand CSS3 text-shadow as well as Internet Explorer, which doesn't.</p>
</div>
<p>Here is the CSS for "compliant" web-browsers:</p>
<blockquote class="code">
<pre>
#basicTextShadow p {
	text-shadow: <span class="hilite2">3px 3px</span> 0px <span class="hilite3">#99cc99</span>;
}
</pre>
</blockquote>
<p>And here is the CSS for IE (using <a href="http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/">Paul Irish’s Conditional CSS Pattern</a>):</p>
<blockquote class="code">
<pre>
body.ie6 #basicTextShadow p,
body.ie7 #basicTextShadow p,
body.ie8 #basicTextShadow p,
body.ie9 #basicTextShadow p {
	zoom: 1;
	background-color: <span class="hilite">#cccccc;</span>
	filter: progid:DXImageTransform.Microsoft.Chroma(Color=<span class="hilite">#cccccc</span>)
	        progid:DXImageTransform.Microsoft.DropShadow(<span class="hilite2">OffX=3, OffY=3</span>, <span class="hilite3">Color=#99cc99</span>);
}
</pre>
</blockquote>
<p><strong>There are some things that you should keep in mind with this solution:</strong></p>
<ul>
<li>Since we are using the <code>Chroma</code> filter to remove the <code>background-color</code> of the object, <strong>any background image or color that you want to appear in the document must be placed in the containing tag</strong>.  In this example, the background-image is styled on a <code>&lt;div&gt;</code> tag, while the text-shadow appears in a <code>&lt;p&gt;</code> tag inside it.</li>
<li><strong>Unlike CSS3, it is impossible to use multiple shadows using Visual Filters</strong> (to be more accurate: it is syntactically possible, but it doesn't look good or behave as one would expect).</li>
<li>According to Microsoft's documentation, <strong>IE8+ is required to have an extra line containing an <code>-ms-filter</code> property</strong> which is identical to the <code>filter</code> one except the property's value is contained on one line within a set of quotation marks.<br />
<blockquote class="code">
<pre>
body.ie6 #basicTextShadow p,
body.ie7 #basicTextShadow p,
body.ie8 #basicTextShadow p,
body.ie9 #basicTextShadow p {
	zoom: 1;
	background-color: #cccccc;
	<span class="hilite">-ms-filter: "progid:DXImageTransform.Microsoft.Chroma(Color=#cccccc) progid:DXImageTransform.Microsoft.DropShadow(Color=#99cc99, OffX=3, OffY=3)";</span>
	filter: progid:DXImageTransform.Microsoft.Chroma(Color=#cccccc)
	        progid:DXImageTransform.Microsoft.DropShadow(OffX=3, OffY=3, Color=#99cc99);
}
</pre>
</blockquote>
<p>I have, however, noticed that the CSS works in IE9 standards mode without this additional line.</li>
</ul>
<h3>Text Glowing</h3>
<p>Text glowing is a term to describe a shadow that "envelopes" some text in a glow of color to make it more legible.  Let's take the following example of black text on a dark background:</p>
<div id="sky" class="test">
<p>This is dark text on a dark background.</p>
</div>
<p>Hard to read, isn't it?  We could change the color of the text to white, but you could also put a white glow around the text to keep it black and maintain the dark atmosphere of the image:</p>
<div id="sky" class="test textShadowTest">
<p>This is dark text on a dark background.</p>
</div>
<p>Using the CSS3 <code>text-shadow</code> property, this is just a case of creating a set of eight shadows around the text in question:</p>
<blockquote class="code">
<pre>
#sky.textShadowTest p {
	text-shadow:
		 0px -1px <span class="hilite2">5px</span> <span class="hilite3">#eeeeee</span>,     /* north      */
		 0px  1px <span class="hilite2">5px</span> <span class="hilite3">#eeeeee</span>,     /* south      */
		-1px  0px <span class="hilite2">5px</span> <span class="hilite3">#eeeeee</span>,     /* west       */
		 1px  0px <span class="hilite2">5px</span> <span class="hilite3">#eeeeee</span>,     /* east       */
		-1px -1px <span class="hilite2">5px</span> <span class="hilite3">#eeeeee</span>,     /* north-west */
		-1px  1px <span class="hilite2">5px</span> <span class="hilite3">#eeeeee</span>,     /* north-east */
		 1px -1px <span class="hilite2">5px</span> <span class="hilite3">#eeeeee</span>,     /* south-west */
		 1px  1px <span class="hilite2">5px</span> <span class="hilite3">#eeeeee</span>;     /* south-east */
}
</pre>
</blockquote>
<p>It basically creates a text-shadow in all eight directions and blurs them together, giving us a glow effect.  Pretty neat, but it doesn't work in Internet Explorer.  However adding this CSS code will give IE something <em>roughly</em> equivalent:</p>
<blockquote class="code">
<pre>

/* Use <a href="http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/"
>Paul Irish’s Conditional CSS Pattern</a> to isolate the rule for Internet Explorer */
body.ie6 #sky.textShadowTest p,
body.ie7 #sky.textShadowTest p,
body.ie8 #sky.textShadowTest p,
body.ie9 #sky.textShadowTest p {
	background-color: #cccccc;
	filter: progid:DXImageTransform.Microsoft.Chroma(Color=#cccccc)
		progid:DXImageTransform.Microsoft.Glow(<span class="hilite2">Strength=5</span>, Color=<span class="hilite3">#eeeeee</span>);
}
</pre>
</blockquote>
<table class="dataTable smallDataTable">
<thead>
<tr>
<th>Firefox using CSS3<br /><code>text-shadow</code></p>
<th>IE using the <code>Chroma</code><br />and <code>Glow</code> Visual Filter.</th>
</tr>
</thead>
<tbody>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/FirefoxGlow.png" alt="" title="FirefoxGlow" width="170" height="92" class="alignnone size-full wp-image-2780" />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/IEGlow.png" alt="" title="FirefoxGlow" width="170" height="92" class="alignnone size-full wp-image-2780" />
</td>
</tbody>
</table>
<p>Note a few things about this solution:</p>
<ol>
<li>The results aren't exactly the same.  Doing a side by side comparison reveals that the CSS3 version looks a little smoother. Here are the above examples blown up 300% to show detail:<br />
<table class="dataTable smallDataTable">
<thead>
<tr>
<th>Firefox using CSS3<br /><code>text-shadow</code></p>
<th>IE using the <code>Chroma</code><br />and <code>Glow</code> Visual Filter.</th>
</tr>
</thead>
<tbody>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/FirefoxGlowScaled.png" alt="" title="FirefoxGlow" width="170" height="92" class="alignnone size-full wp-image-2780" />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/IEGlowScaled.png" alt="" title="FirefoxGlow" width="170" height="92" class="alignnone size-full wp-image-2780" />
</td>
</tbody>
</table>
</li>
<li>The <code>Strength</code> in the <code>Glow</code> filter is the same amount of pixels in the blur-factor in the CSS3 <code>text-shadow</code> code.</li>
<li>You'll notice that <code>background-color</code> I removed with the <code>Chroma</code> filter in this case is not blue, but gray, a color halfway between the color of the text (black) and the color or the glowing text (white).  This is so that the smoothness obtained by ClearType is somewhat preserved. Choosing black would make the text look to "thick", while choosing white would make the text look too "thin".</li>
<li>You'll notice the IE glowing text is "pushed" a little down and to the right.  That's because IE treats the <code>Glow</code> as part of the width and height of the element.  This can be fixed by relatively positioning the object and setting the <code>top</code> and <code>left</code> properties to the negative value of <code>Glow</code>'s <code>Strength</code> value to compensate:<br />
<blockquote class="code">
<pre>
body.ie6 #sky.textShadowTest p,
body.ie7 #sky.textShadowTest p,
body.ie8 #sky.textShadowTest p,
body.ie9 #sky.textShadowTest p {
	zoom: 1;
	background-color: #cccccc;
	filter: progid:DXImageTransform.Microsoft.Chroma(Color=#cccccc)
		progid:DXImageTransform.Microsoft.Glow(Color=#eeeeee, Strength=3);
	<span class="hilite">position: relative;</span>
	<span class="hilite">top: -3px;</span>
	<span class="hilite">left: -3px;</span>
}
</pre>
</blockquote>
<p>The results are subtle, but will help to make the result a little more pixel perfect. </p>
<table class="dataTable smallDataTable">
<thead>
<tr>
<th>Firefox using CSS3<br /><code>text-shadow</code></p>
<th>IE using the modified<br />version of the <code>Chroma</code><br />fix.</th>
<th>IE using the both <br />positioning and modified<br /><code>Chroma</code><br />fix.</th>
</tr>
</thead>
<tbody>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/FirefoxGlow.png" alt="" title="FirefoxGlow" width="170" height="92" class="alignnone size-full wp-image-2780" />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/IEGlow.png" alt="" title="FirefoxGlow" width="170" height="92" class="alignnone size-full wp-image-2780" />
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/IEGlow2.png" alt="" title="FirefoxGlow" width="170" height="92" class="alignnone size-full wp-image-2780" />
</td>
</tbody>
</table>
<p> If you don't like using relatively positioning the text, you can also use negative left and top margins to achieve the same effect, or you can leave it the way it is &mdash; after all, what are a few pixels between friends? ;-)</p>
</li>
</ol>
<p>I have used this method in <a href="/blog/2011/03/29/pixel-perfect-css3-border-image-in-depth/">my previous blog post</a> about CSS3 <code>border-image</code>:</p>
<table class="dataTable">
<thead>
<tr>
<th>Firefox</th>
<th>IE9</th>
</thead>
<tbody>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/03/firefoxFallback.png" alt="Screenshot of how the border-image example at the top of the page looks in Firefox." title="Screenshot of how the border-image example at the top of the page looks in Firefox." width="355" height="284" class="size-full wp-image-2634" /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/03/IEfallback.png" alt="Screenshot of how the border-image example &#039;falls back&#039; in IE9." title="Screenshot of how the border-image example &#039;falls back&#039; in IE9." width="362" height="291" class="size-full wp-image-2633" /></td>
</tbody>
</table>
<p>Here is the CSS that I used to produce it:</p>
<blockquote class="code">
<pre>
#introExample p, #introExample code {
   color: white;
   text-shadow:   2px  2px 3px #333333,
                 -2px -2px 3px #333333,
                 -2px  2px 3px #333333,
                  2px -2px 3px #333333;
}

/*
 * The "poor man's" version of text-shadow for IE's Visual filters.
 */
body.ie6 #introExample p,
body.ie7 #introExample p,
body.ie8 #introExample p,
body.ie9 #introExample p {
	zoom: 1;
	background: #000003;
	filter: progid:DXImageTransform.Microsoft.Chroma(Color=#000003)
		progid:DXImageTransform.Microsoft.Glow(Color=#3e3e3e, Strength=4); 

}
</pre>
</blockquote>
<p>The values of the Visual Filter code doesn't match exactly with the <code>text-shadow</code>.  This is in part that I only used four directions in the <code>text-shadow</code> code (i.e. south-east, north-west, north-east and south-west).  I don't believe this conversion is an exact science ... it is worth your time to experiment with these values, using the examples in this article as a guide.</p>
<h2>But How About Other Types Of Shadows?</h2>
<p><strike>The short answer for now is that you are out of luck.  There are no Visual Filters, as far as I know, that will allow you to do other types of shadowing, like a Basic Text-Shadow with blurring:</strike> <strong>Update April 24, 2011:</strong> Since writing this article, I have a discovered <a href="http://www.useragentman.com/blog/2011/04/23/css-blurred-text-shadow-in-ie-part-i/">a way to implement blurred text-shadows in IE8+</a>.  I have left the rest of the information here since it is still relevant, interesting and influenced my own work.</p>
<p><div id="attachment_2848" class="wp-caption aligncenter" style="width: 390px"><a href="http://www.useragentman.com/blog/wp-content/uploads/2011/04/example2.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/04/example2.png" alt="An example of a basic text shadow with blurring." title="example2" width="380" height="90" class="size-full wp-image-2848" /></a><p class="wp-caption-text">There is no way that I know to do this in IE without JavaScript or without affecting the DOM</p></div></p>
<p><a href="http://kilianvalkhof.com/">Kilian Valkhob</a> also has <a href="http://kilianvalkhof.com/2008/design/almost-cross-browser-text-shadow/">a solution for this</a> which involves making a copy of the desired text and blurring it with the <a href="http://msdn.microsoft.com/en-us/library/ms532979%28v=vs.85%29.aspx"><code>Blur</code> filter</a>. While I think the results look pretty good, I hesitate using this method since search engines may see the text repeated in the document and index that text higher than it should be rated (or they might penalize the document because the search engine thinks the author is trying to do some unethical hack of the page ranking algorithm it uses).  Vilkhob has, however, also created a <a href="http://kilianvalkhof.com/2008/javascript/text-shadow-in-ie-with-jquery/">text-shadowing JavaScript library</a> that automates this process, and since the repeated text isn't actually in the document, it may be a solution to the search engine concern.  This solution is something i am currently looking into adding to cssSandpaper, but I want to do more research into this before I implement it in a public version of my library. For example, how would screen readers handle this JavaScript generated "double text"?  </p>
<h2>Conclusion</h2>
<p>CSS3 <code>text-shadow</code> is a great effect in a web developer's toolkit.  Hopefully IE will natively support it soon, but in the meantime, at least there are some use cases you can use Visual Filters to do some of eye-candy it supports.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2011/04/14/css3-text-shadow-can-it-be-done-in-ie-without-javascript/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Pixel Perfect CSS3 border-image In Depth.</title>
		<link>http://www.useragentman.com/blog/2011/03/29/pixel-perfect-css3-border-image-in-depth/</link>
		<comments>http://www.useragentman.com/blog/2011/03/29/pixel-perfect-css3-border-image-in-depth/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 04:18:55 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[border-image]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=2536</guid>
		<description><![CDATA[<img src="/blog/wp-content/uploads/2011/03/front.png" /> Using the CSS3 <code>border-image</code> property, you can make coo graphical borders without cutting up images to bits. There are a few gotchas that developers should be aware of before implementing it and this article will cover these caveats, a tool that you can use to help generate border-images effectively, and a few strategies to ensure it gracefully degrades in older browsers]]></description>
			<content:encoded><![CDATA[<div id="introExample" class="alignLeft">
<p>This is an example of CSS3 <code>border-image</code> in action. Browsers that don&#8217;t support it will see a normal solid coloured <code>border</code>, while modern browsers will see a nice framed <code>border-image</code>. Note that the clouds are produced with an additional <code>background-image</code>, showing the possibility of having separate images for borders and backgrounds.</p>
</div>
<p>The <code>border-image</code> property is something I&#8217;ve been wanting for a long time. For years, I have been cutting up images into several pieces in order to emulate this effect (the most recent example of this was used in <a href="/tests/fontConverter/ArgBiwSc.html">this demo</a> of the <a href="/blog/2011/02/20/converting-font-face-fonts-quickly-in-any-os/">CSS3 Font Converter</a>).  The difference is that <strong>CSS3&#8242;s border-image property uses only one image and two lines of CSS</strong> (well &#8230; 6 if you include the vendor-specific properties and the fallback for browsers that don&#8217;t support it).</p>
<p>Since it is newly implemented in most web browsers, there are a few gotchas that developers should be aware of before implementing <code>border-image</code>.  This article will cover these caveats, a tool that you can use to help generate border-images effectively, and a few things you should keep in mind so that pages don&#8217;t look funny in browsers that don&#8217;t support <code>border-radius</code>.  </p>
<h2>Let&#8217;s Look At An Example</h2>
<div id="example1">
<p>This is an example of a block level element that uses the  <code>border-image</code> property.  The <code>border-image</code> is viewable in all major browsers except for IE (more on that later).  It <strong>uses only one image</strong> to produce the border &mdash; no images were cut-up into pieces or harmed in any other way.  The code to generate this border is fairly straight-forward once you know how it works:</p>
<blockquote class="code">
<pre>
#object {

   /*
    * These border widths must match the border-image numbers.
    */
    border-width: 23px 22px 22px 26px;

   /*
    * Note that all browsers use their respective vendor prefix.  Also note
    * that, unlike the border-width values, the widths in the border-image
    * property don't have the 'px' unit at the end.
    */
   -moz-border-image:    url('image.png') 23 22 22 26 round round;
   -webkit-border-image: url('image.png') 23 22 22 26 round round;
   -o-border-image:      url('image.png') 23 22 22 26 round round;
   border-image:         url('image.png') 23 22 22 26 round round;

   /*
    * You should include a border-color and border-style as a fallback for
    * browsers that don't support border-image
    */
    border-color: #cccccc;
    border-style: solid;
 }
</pre>
</blockquote>
<div class="centered">
The original image looks like this:<br />
<img src="/border-image/images/borders/chain.png" alt="image of a chain" /><br />
It is an edited version of an image produced by <a href="http://www.free-printable-borders.com/">Free Printable Borders</a>.
</div>
</div>
<p>Note that the image repeats to the size of the block it borders.  When you design a <code>border-image</code>, the border should tile in a similar way that a <code>background-image</code> does.  There are some major differences though, so let&#8217;s show in depth how <code>border-image</code> is used, and introduce you to the tool that will help even the laziest developer in the world (i.e. me) create them quickly.</p>
<h2>Basic Syntax</h2>
<p>Note that the basic CSS is quite easy if you know how <code>border-width</code> works:</p>
<blockquote class="code">
<pre>
#selector {

  border-width: <em>&lt;top-width&gt;</em>px <em>&lt;right-width&gt;</em>px <em>&lt;bottom-width&gt;</em>px <em>&lt;left-width&gt;</em>px;

  border-image: url(<em>&lt;image-url&gt;</em>) <em>&lt;top-width&gt;</em> <em>&lt;right-width&gt;</em> <em>&lt;bottom-width&gt;</em> <em>&lt;left-width&gt;</em> 
                <em>&lt;horizontal-effect&gt;</em> <em>&lt;vertical-effect&gt;</em>;

}
</pre>
</blockquote>
<p>Note that if you are measuring your widths in pixels, then you must put the <code>px</code> unit inside the <code>border-width</code> declaration, but you must leave it out in the <code>border-image</code> one.  I know it doesn&#8217;t seem logical, but it&#8217;s just the way it is.</p>
<p>To illustrate the all of the <code>border-image</code> parameters, let&#8217;s take this image:</p>
<div class="centered">
<img src="/border-image/images/borders/border.png" alt="image of a border" />
</div>
<p>First we must grab the border widths in the right order:</p>
<p><div id="attachment_2568" class="wp-caption aligncenter" style="width: 396px"><a href="http://www.useragentman.com/blog/wp-content/uploads/2011/03/diagram.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/03/diagram.png" alt="A diagram showing how the borders widths are ordered." title="diagram" width="386" height="198" class="size-full wp-image-2568" /></a><p class="wp-caption-text">A diagram showing how the borders widths are ordered.</p></div></p>
<p>(Note that the order of the <code>border-image</code> widths is consistent with the order that <code>margin</code> and <code>padding</code> uses).  </p>
<p>Now, let us apply effects on our image.</p>
<table class="dataTable">
<thead>
<tr>
<th>Pure CSS Example (will be visible if your browser supports <code>border-image</code></th>
<th>Firefox Screenshot (Opera and Webkit are similar, except for the <code>round</code> effect, which Chrome and Safari currently don&#8217;t support.)</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div id="stretchExample" class="example2">
This is an example of a stretched border.  Note that the square in the corner remains intact, while the other squares are the ones that stretch.
</div>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/03/stretch.png" alt="Screenshot of border-image with stretch effect." title="stretch" class="alignnone size-full wp-image-2600" />
</td>
</tr>
<tr>
<td>
<div id="repeatExample" class="example2">
This is an example of a repeated border.   You&#8217;ll note that the browser will apply symmetry  on the border, so that it looks &#8220;balanced&#8221;.
</div>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/03/repeat.png" alt="Screenshot of border-image with repeat effect." title="repeat" class="alignnone size-full wp-image-2600" /></p>
</td>
</tr>
<tr>
<td>
<div id="roundExample" class="example2">
This is an  example of a rounded border.  In this example, the browser tries to &#8220;round&#8221; the widths and lengths of the squares so they are not abruptly cut off.  <strong>Currently, this property is only supported by Firefox and Opera.</strong>
</div>
</td>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/03/round.png" alt="Screenshot of border-image with round effect." title="round" class="alignnone size-full wp-image-2600" />
</td>
</tr>
</tbody>
</table>
<h2>But I <em>Hate</em> Counting Pixels!</h2>
<p>If you are the laziest developer in the world (i.e. me), you don&#8217;t want to crack open your graphics editor, open up a image file and count the pixels by hand &#8211; you want a tool that will generate the CSS for you.  After all, don&#8217;t we use computers so that they will do things for us?  At least, <a href="http://www.youtube.com/watch?v=bBBw9E2Q_aY">until they take over the world?</a></p>
<p>I was in the middle of creating my own tool, but I noticed that  <a href="http://www.incaseofstairs.com/">Kevin Decker</a> beat me to it with his excellent <a href="http://www.border-image.com/">Border Image Generator</a>.  You can take any image, from the web or your desktop, drag a few sliders around, and <em>voil&aacute;!</em>, you have your code, vendor-prefixes and all. You should definitely check it out if you are as lazy as I am.</p>
<h2>Percentage Widths</h2>
<p>The <code>border-image</code> property can also take percentage values, which correspond to the image&#8217;s width in height.  For example, let&#8217;s take this 81&#215;81 image:</p>
<div class="centered">
<img src="/border-image/images/borders/chain.png" alt="image of a border" />
</div>
<p>As you recall, we used the following pixel dimensions:</p>
<blockquote class="code">
<pre>
border-image: url('/border-image/images/borders/chain.png') 23 22 22 26 round;
</pre>
</blockquote>
<p>If you wanted to convert the pixel widths to percentages, you must take each value and divide it by either the entire width of the <code>border-image</code> (for the left and right widths) or by the height of the <code>border-image</code> (for the top and bottom widths).  In the above case:</p>
<ul>
<li>The top border width percentage = (top border width in pixels) / (<code>border-image</code> height) = 23 / 81 = 0.283&#8230; = 28%</li>
<li>The right border width percentage = (right border width in pixels) / (<code>border-image</code> width) = 22 / 81 = 0.271&#8230; = 27%</li>
<li>The bottom border width percentage = (bottom border width in pixels) / (<code>border-image</code> height) = 22 / 81 = 0.271 = 27%</li>
<li>The left border width percentage = (left border width in pixels) / (<code>border-image</code> width) = 26 / 81 = 0.320 = 32%</li>
</ul>
<p>Note that these percentages can only be used in the <code>border-image</code> property.  The <code>border-width</code> property must continue to use the pixel values:</p>
<div id="percentageExample">
This is the CSS used to generate this:</p>
<blockquote class="code">
<pre>
   /*
    * These border widths must match the border-image numbers
    */
    border-width: 23px 22px 22px 26px;
 	border-color: black;
   /*
    * Note that all browsers use their respective vendor prefix.
    */
   -moz-border-image:    url('chain.png') 28% 27% 27% 32% round;
   -webkit-border-image: url('chain.png') 28% 27% 27% 32% round;
   -o-border-image:      url('chain.png') 28% 27% 27% 32% round;
   border-image:         url('chain.png') 28% 27% 27% 32% round;
</pre>
</blockquote>
</div>
<p>Now, why on earth would you want to use percentages, since pixels are probably more accurate?  I don&#8217;t see there being any need for bitmap images, but <strong>Webkit browsers (i.e. Safari and Chrome) can use SVG vector images as a <code>border-image</code> as well</strong>.  Since SVG images are resolution independent, I would assume it is more accurate to use percentages.  It would be worth looking into percentage widths more when SVG border-image support reaches critical mass, since the other browser manufacturers may handle SVG support differently than Webkit.</p>
<h2>Degrading Gracefully and Progressive Enhancement</h2>
<p>It is important that developers ensure their designs degrade gracefully so that pages not only <strong>look decent in browsers that don&#8217;t support <code>border-image</code></strong>, but also look nice when a compliant browser is loading the images, especially <strong>when loading a high-bandwidth page or a page on a slow connection</strong>.  Not only should you ensure the <code>border-color</code> and <code>border-style</code> are set, but it is a good idea to ensure that the look of the fallback border is as close as possible to border-image as possible.  Let&#8217;s take a look at the &#8220;framed border&#8221; we used at the top of this page:</p>
<table class="dataTable">
<thead>
<tr>
<th>Firefox</th>
<th>IE9</th>
</thead>
<tbody>
<td><div id="attachment_2634" class="wp-caption alignnone" style="width: 365px"><a href="http://www.useragentman.com/blog/wp-content/uploads/2011/03/firefoxFallback.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/03/firefoxFallback.png" alt="Screenshot of how the border-image example at the top of the page looks in Firefox." title="Screenshot of how the border-image example at the top of the page looks in Firefox." width="355" height="284" class="size-full wp-image-2634" /></a><p class="wp-caption-text">Screenshot of how the border-image example at the top of the page looks in Firefox.</p></div></td>
<td><div id="attachment_2633" class="wp-caption alignnone" style="width: 372px"><a href="http://www.useragentman.com/blog/wp-content/uploads/2011/03/IEfallback.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/03/IEfallback.png" alt="Screenshot of how the border-image example &#039;falls back&#039; in IE9." title="Screenshot of how the border-image example &#039;falls back&#039; in IE9." width="362" height="291" class="size-full wp-image-2633" /></a><p class="wp-caption-text">Screenshot of how the border-image example 'falls back' in IE9 using the ridge border-style.</p></div></td>
</tbody>
</table>
<p>You can also be fancy and use <a href="http://www.modernizr.com">modernizr</a> to do some extra progressive enhancement styling by using the <br /><code>html.no-borderimage</code> selector.  I have done this using the comments section of my blog posts.</p>
<table class="dataTable">
<thead>
<tr>
<th>Firefox</th>
<th>IE9</th>
</thead>
<tbody>
<td><div id="attachment_2639" class="wp-caption alignnone" style="width: 310px"><a href="http://www.useragentman.com/blog/wp-content/uploads/2011/03/firefoxBalloon.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/03/firefoxBalloon-300x106.png" alt="Screen shot of comment on my blog using the balloon border-image in firefox." title="Screen shot of comment on my blog using the balloon border-image in firefox (Click to see full screenshot)." width="300" height="106" class="size-medium wp-image-2639" /></a><p class="wp-caption-text">Screen shot of comment on my blog using the balloon border-image in firefox (Click to see full screenshot).</p></div></td>
<td><div id="attachment_2638" class="wp-caption alignnone" style="width: 310px"><a href="http://www.useragentman.com/blog/wp-content/uploads/2011/03/ieBalloonFallback.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2011/03/ieBalloonFallback-300x66.png" alt="Screen shot of the same comment using modernizr to style the comment differently on browsers that don&#039;t support border-image (Click to see full screenshot)." title="Screen shot of the same comment using modernizr to style the comment differently on browsers that don&#039;t support border-image (Click to see full screenshot)." width="300" height="66" class="size-medium wp-image-2638" /></a><p class="wp-caption-text">Screen shot of the same comment using modernizr to style the comment differently on browsers that don't support border-image (Click to see full screenshot).</p></div></td>
</tbody>
</table>
<h2>Using With Background Images</h2>
<p>If you are using a <code>border-image</code> without a transparent colour or alpha channel, the center of your <code>border-image</code> will hide any <code>background-image</code> the object may have.  If you want to have a separate <code>background-image</code>, you must &#8220;cut-out&#8221; the middle of the <code>border-image</code> using your graphics editor with a transparent colour.  For instance, the example at the top of the page with the picture frame <code>border-image</code> has a photo of clouds as a <code>background-image</code>.   This allows developers to create more graphically rich block-level elements.</p>
<h2>Hey! What about IE?</h2>
<p>Unfortunately, IE doesn&#8217;t support <code>border-image</code> natively.  <strong>I <em>may</em> have a workaround for this using cssSandpaper</strong>, but it needs a lot more testing to see if it is a truly viable polyfill for this effect.  If I am successful,  I will post whether that solution as an addendum to this blog post.</p>
<h2>Conclusion</h2>
<p><code>border-image</code> can be used today to make some very interesting effects that can be degraded gracefully in browsers that don&#8217;t support it.  It can speed up design time considerably since you don&#8217;t have to use your graphics editor to cut up images.  And I&#8217;m sure it will waste a lot of your time while you play and see how it can be used effectively.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2011/03/29/pixel-perfect-css3-border-image-in-depth/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

