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

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

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

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

   var $loader,
       currentImage = 0;

   me.init = function () {

      var s = [];

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

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

   }

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

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

   ....

}

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

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

  body.loaded #content {
     display: block;
  }

  body.loaded #progressContainer {
     display: none !important;
  }
</pre>
</blockquote>
<h2>Can We Show Other Things Loading in the Progress Bar Besides Images?</h2>
<p>It is possible to show CSS and JavaScript in the progress bar using <a href="http://yepnopejs.com/">yepnope.js</a>.  It is a little bit more involved, but very doable (I have done it before), and I leave it as an exercise to the reader to do it.  Post it below, and I&#8217;ll give you full geek-cred.  If no one does it, I will probably take some time and publish an example in a few weeks, but I thought it would be neat to offer up a little challenge. :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2012/01/16/caching-images-with-javascript-and-html5-progress-bars/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>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>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>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>

