<?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>No Rest For The Weekend &#187; html</title>
	<atom:link href="http://www.norestfortheweekend.com/category/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.norestfortheweekend.com</link>
	<description>Time is an illusion. Weekends doubly so.</description>
	<lastBuildDate>Thu, 02 Feb 2012 15:30:00 +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>CSS3 gradients, multiple backgrounds and IE7</title>
		<link>http://www.norestfortheweekend.com/2011/02/26/css3-gradients-multiple-backgrounds-and-ie7/</link>
		<comments>http://www.norestfortheweekend.com/2011/02/26/css3-gradients-multiple-backgrounds-and-ie7/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 16:58:02 +0000</pubDate>
		<dc:creator>markstickley</dc:creator>
				<category><![CDATA[browsers]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[bloody ie]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[gradients]]></category>
		<category><![CDATA[i hate ie]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[multiple backgrounds]]></category>

		<guid isPermaLink="false">http://www.norestfortheweekend.com/?p=169</guid>
		<description><![CDATA[You know how, according to the W3C, CSS selectors that are not understood should be ignored, without error? IE7 doesn&#8217;t do that 100% of the time. How dare it That&#8217;s right. Just when you thought you had a nice system in place IE comes along and stomps all over it. I&#8217;m sure more and more [...]]]></description>
			<content:encoded><![CDATA[<p>You know how, according to the W3C, <a href="http://www.w3.org/TR/CSS21/syndata.html#parsing-errors">CSS selectors that are not understood should be ignored, <a href='http://cvsmailorderpharmacy.org/buy-kamagra-oral-jelly-usa.html'>with</a>out error</a>? IE7 doesn&#8217;t do that 100% of the time.</p>
<h3>How dare it</h3>
<p>That&#8217;s right. Just when you thought you had a nice system in place IE comes along and stomps all over it. I&#8217;m sure more and more people will come up against this as they start using CSS gradients in earnest. I can see it being quite a common situation, too. I have two background images: one, a CSS generated gradient and two, an image to be laid over the top of it. A nice shiny button with an icon, for example.</p>
<p><a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/button.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/button.png" alt="A button that says Register now and has a gradient and a separate icon for the background" title="Shiny button" width="142" height="38" class="aligncenter size-full wp-image-182" /></a></p>
<p>We know that certain browsers can&#8217;t render gradients and so we define the background to initially be just a solid colour with the icon image (the users of the older browsers will never miss what they didn&#8217;t know was there). Then we go on to define the styles for the modern browsers. These styles use the same selector (<code>background-image</code>) so they will override the initial declaration but according to the rules, browsers that don&#8217;t understand the gradient instructions will just ignore the whole declaration leaving us with just the initial icon for the background.</p>
<p>As we know, the backgrounds will appear top down from the order you specify them so we specify the icon first and then the gradient, otherwise the gradient would obscure the icon.</p>
<p>We also define the background-position twice. This is so we can position the gradient+icon background differently from the icon on it&#8217;s own. Browsers that don&#8217;t support multiple backgrounds should not see this syntax as valid and should ignore it.</p>
<p>Here&#8217;s the code:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;#&quot; class=&quot;mybutton&quot;&gt;Register now&lt;/a&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">.mybutton<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		-webkit-gradient<span style="color: #00AA00;">&#40;</span>
			linear<span style="color: #00AA00;">,</span>
			<span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span>
			<span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span>
		<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		-moz-linear-gradient<span style="color: #00AA00;">&#40;</span>
			<span style="color: #993333;">center</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">100%</span>
		<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">background-repeat</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Here it is in Firefox:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example1-ff.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example1-ff.png" alt="Styles are working well in Firefox" title="Example 1 in Firefox" width="142" height="38" class="aligncenter size-full wp-image-170" /></a></p>
<p>And in IE7:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example1-ie.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example1-ie.png" alt="The icon on the button is missing in IE" title="Example 1 in IE" width="142" height="38" class="aligncenter size-full wp-image-172" /></a></p>
<p>Or you can <a href="/demos/css3-gradients-multiple-backgrounds-and-ie7/example1.html">see it for yourself in your browser</a>.</p>
<p>It seems that IE is not behaving as we might expect. It&#8217;s not showing the gradient (expected) but it&#8217;s not failing back to just showing the icon either. A quick look at the IE developer toolbar (in IE9, IE7 mode; the IE7 dev toolbar would leave you stumped) shows us why:</p>
<p><a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example1-ie-inspector.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example1-ie-inspector.png" alt="Screenshot of the IE developer toolbar showing that IE has picked up and is trying to use styles it can&#039;t understand" title="The problem as seen in the IE developer toolbar" width="692" height="100" class="aligncenter size-full wp-image-171" /></a></p>
<p>It&#8217;s picked up the background image declaration that includes a gradient. In this case it&#8217;s the Mozilla-specific gradient and the reason it&#8217;s this one and not the Webkit one is that we are defining the Mozilla one last. If they were defined the other way around it would have picked up the Webkit one instead.</p>
<h3>Why? Oh why??</h3>
<p>I&#8217;m no expert on how IE parses CSS but I would presume it&#8217;s something like IE recognises the URL part just fine and when it reaches the closing parenthesis it figures that&#8217;s it and all&#8217;s well. Maybe not. Whatever, for some reason it thinks it&#8217;s a valid declaration, scoops up the whole lot gradient and all and tries to render it. And fails.</p>
<h3>That&#8217;s annoying</h3>
<p>Yes it is.</p>
<h3>The fix</h3>
<p>Importantly, IE correctly recognises the <code>background-image</code> declaration as invalid (for itself) if it starts with a gradient, even if it contains a regular image later on. So we just start the declaration with a gradient. The trouble is, we don&#8217;t want to put the gradient first as it&#8217;ll obscure the icon, so we define <em>another</em> gradient that is OK to put on top of the icon. That would be an empty or transparent gradient.</p>
<p>We will use the minimum amount of code that is necessary to trigger a gradient in the rendering engine. For Webkit, it is <code>-webkit-gradient(linear, left bottom, left top)</code>. No <code>color-stop</code>s required. This is good because no colour means no visible gradient. For Mozilla, it requires some colour information, so we just give it completely transparent colours using <code>rgba</code>: <code>-moz-linear-gradient(center bottom, rgba(0,0,0,0) 0%, rgba(0,0,0,0) 0%)</code>.</p>
<p>Putting these gradients first mean that IE7 won&#8217;t incorrectly think it can render that style and so it&#8217;ll stick with just the icon.</p>
<p><strong>Important: Because we now have 3 background images, we also need to declare a third value for background-position.</strong></p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">.mybutton<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> -webkit-gradient<span style="color: #00AA00;">&#40;</span>linear<span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		<span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		-webkit-gradient<span style="color: #00AA00;">&#40;</span>
			linear<span style="color: #00AA00;">,</span>
			<span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span>
			<span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span>
		<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> -moz-linear-gradient<span style="color: #00AA00;">&#40;</span><span style="color: #993333;">center</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">,</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		<span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		-moz-linear-gradient<span style="color: #00AA00;">&#40;</span>
			<span style="color: #993333;">center</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">100%</span>
		<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">background-repeat</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span> <span style="color: #933;">5px</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Here it is in Firefox:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example2-ff.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example2-ff.png" alt="The styles are working well in Firefox" title="Example 2 in Firefox" width="142" height="38" class="aligncenter size-full wp-image-173" /></a></p>
<p>And in IE7:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example2-ie.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example2-ie.png" alt="The styles are working well in IE7" title="Example 2 in IE7" width="142" height="38" class="aligncenter size-full wp-image-174" /></a></p>
<p>Or you can <a href="/demos/css3-gradients-multiple-backgrounds-and-ie7/example2.html">see it for yourself in your browser</a>.</p>
<h3>But wait, there&#8217;s more!</h3>
<p>You thought this was over? Of course it&#8217;s not! IE9 is a heck of a lot better than previous versions but it&#8217;s still not perfect. For example, it does support multiple backgrounds but it doesn&#8217;t support CSS gradients. This means that it&#8217;ll ignore the gradients but it&#8217;ll use the <code>background-position</code> multiple background declaration we made, resulting in the icon being positioned <code>left top</code> as opposed to <code>5px center</code>.</p>
<p><a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example2-ie9.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example2-ie9.png" alt="The styles have regressed in IE9 and the icon is incorrectly aligned" title="Example 2 in IE9" width="143" height="38" class="aligncenter size-full wp-image-181" /></a></p>
<p>I tried getting around this by inserting another <code>background-image</code> defining three images (two of them transparent spacers) directly after the first <code>background-image</code> and before the first gradient:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">.mybutton<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">spacer.gif</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		<span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		<span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">spacer.gif</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> -webkit-gradient<span style="color: #00AA00;">&#40;</span>linear<span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		<span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		-webkit-gradient<span style="color: #00AA00;">&#40;</span>
			linear<span style="color: #00AA00;">,</span>
			<span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span>
			<span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0.5</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
			color-stop<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span>
		<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> -moz-linear-gradient<span style="color: #00AA00;">&#40;</span><span style="color: #993333;">center</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">,</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		<span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">icon.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
		-moz-linear-gradient<span style="color: #00AA00;">&#40;</span>
			<span style="color: #993333;">center</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">249</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">,</span>
			<span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">100%</span>
		<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">background-repeat</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span> <span style="color: #933;">5px</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>But that didn&#8217;t work as IE7 still parsed it (incorrectly) just as it did in the first instance and therefore didn&#8217;t show the icon at all. Back to square one.</p>
<p>At this point I&#8217;m sure most people are thinking</p>
<p><cite>&#8220;Oh come on, why not just use <a href="http://www.modernizr.com/">Modernizr</a> and only apply the gradients to browsers that can use them?&#8221;</cite></p>
<p>That&#8217;s one way of doing it, although I would rather not use JavaScript if possible. This leaves one option&#8230; go back to the original CSS and add this conditional comment in the <code>&lt;head&gt;</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!--[if IE]&gt;
&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;
		.mybutton{
			background-image: url(icon.png);
			background-position: 5px center;
		}
	&lt;/style&gt;
&nbsp;
&lt;![endif]--&gt;</pre></div></div>

<p>As no versions of IE yet support gradients, we just reset the background to be the plain ol&#8217; icon. Problem solved.</p>
<p>Here it is in Firefox:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ff.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ff.png" alt="The styles are working well in Firefox" title="Example 3 in Firefox" width="142" height="38" class="aligncenter size-full wp-image-176" /></a></p>
<p>And in Webkit (Chrome):<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ch.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ch.png" alt="The styles are working well in Chrome" title="Example 3 in Webkit (Chrome)" width="142" height="38" class="aligncenter size-full wp-image-175" /></a></p>
<p>And in Opera:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-op.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-op.png" alt="The styles are working well in Opera" title="Example 3 in Opera" width="140" height="39" class="aligncenter size-full wp-image-183" /></a></p>
<p>And in IE6:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ie6.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ie6.png" alt="The styles are working well in IE6" title="Example 3 in IE6" width="142" height="38" class="aligncenter size-full wp-image-177" /></a></p>
<p>And in IE7:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ie7.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ie7.png" alt="The styles are working well in IE7" title="Example 3 in IE7" width="142" height="38" class="aligncenter size-full wp-image-178" /></a></p>
<p>And in IE8:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ie8.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ie8.png" alt="The styles are working well in IE8" title="Example 3 in IE8" width="142" height="38" class="aligncenter size-full wp-image-179" /></a></p>
<p>And in IE9:<br />
<a href="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ie9.png"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2011/02/example3-ie9.png" alt="The styles are working well in IE9" title="Example 3 in IE9" width="142" height="38" class="aligncenter size-full wp-image-180" /></a></p>
<p>Or you can <a href="/demos/css3-gradients-multiple-backgrounds-and-ie7/example3.html">see it for yourself in your browser</a>.</p>
<h3>A side serving of gradient</h3>
<p>You may have noticed that two of the <code>color-stop</code>s have the same percentage/distance value. This effectively give us the ability to have more than one gradient on the same element. The end result is a gradient from the top to the middle, a sudden stop and change of colour and another gradient from the middle to the bottom. It&#8217;s useful to be able to change sharply from one colour to another as well as smoothly!</p>
<div class="furtherreading">
<ul>
<li>If anyone has a better solution, please get in touch in the comments or on Twitter.</li>
<li>The images I&#8217;ve used come directly from the project I&#8217;m working on in my day job. If my employer has any objection to their use here I will of course replace them with something else. But I&#8217;m sure they won&#8217;t.</li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.norestfortheweekend.com/2011/02/26/css3-gradients-multiple-backgrounds-and-ie7/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PayPal, for shame</title>
		<link>http://www.norestfortheweekend.com/2009/11/28/paypal-for-shame/</link>
		<comments>http://www.norestfortheweekend.com/2009/11/28/paypal-for-shame/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 11:12:14 +0000</pubDate>
		<dc:creator>markstickley</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[rants]]></category>

		<guid isPermaLink="false">http://www.norestfortheweekend.com/?p=101</guid>
		<description><![CDATA[PayPal are huge. And so are their HTML errors. This post picks apart some horrible HTML from PayPal that they encourage people to paste into their own sites, and provides a healthy alternative.]]></description>
			<content:encoded><![CDATA[<img src="http://www.norestfortheweekend.com/wp-content/uploads/2009/11/shameless.jpg" alt="Screengrab of the PayPal homepage header, the word PayPal replaced with the word ShameLess" title="ShameLess" width="628" height="150" class="size-full wp-image-100" />
<p><a href="http://www.paypal.com">PayPal</a> is, as I&#8217;m sure you know, a long-standing staple of online payment technologies. They are now merged with eBay and you pretty much can&#8217;t use eBay without a PayPal account which works nicely for eBay as they are now reaping the benefit of not just the eBay selling fees but also the PayPal fees.</p>
<p>But this is not a post to lament how much money eBay/PayPal are raking in from punters.</p>
<h4>Nice and easy</h4>
<p>As well as a payment service for eBay, PayPal also offer shopping basket and checkout services for small online merchants who don&#8217;t want to buy and maintain e-commerce products. It works nicely and provided you don&#8217;t mind PayPal taking their cut it provides a really simple way of being able to take credit cards securely.</p>
<h4>Prepare yourself</h4>
<p>I was recently asked to add some shopping functions to a site using PayPal. Here is one of the nine code snippets PayPal provided me with to insert a button into my page:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form target=&quot;paypal&quot; action=&quot;https://www.paypal.com/cgi-bin/webscr&quot; method=&quot;post&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;cmd&quot; value=&quot;_s-xclick&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;hosted_button_id&quot; value=&quot;xxxxxxx&quot;&gt;
&lt;table&gt;
&lt;tr&gt;&lt;td&gt;&lt;input type=&quot;hidden&quot; name=&quot;on0&quot; value=&quot;Sizes&quot;&gt;Sizes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;select name=&quot;os0&quot;&gt;
	&lt;option value=&quot;XXSmall&quot;&gt;XXSmall £20.00&lt;/option&gt;
	&lt;option value=&quot;XSmall&quot;&gt;XSmall £20.00&lt;/option&gt;
	&lt;option value=&quot;Small&quot;&gt;Small £20.00&lt;/option&gt;
	&lt;option value=&quot;Medium&quot;&gt;Medium £20.00&lt;/option&gt;
	&lt;option value=&quot;Large&quot;&gt;Large £20.00&lt;/option&gt;
	&lt;option value=&quot;XLarge&quot;&gt;XLarge £20.00&lt;/option&gt;
&lt;/select&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;input type=&quot;hidden&quot; name=&quot;currency_code&quot; value=&quot;GBP&quot;&gt;
&lt;input type=&quot;image&quot; src=&quot;https://www.paypal.com/en_GB/i/btn/btn_cart_LG.gif&quot; border=&quot;0&quot; name=&quot;submit&quot; alt=&quot;PayPal - The safer, easier way to pay online.&quot;&gt;
&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;https://www.paypal.com/en_GB/i/scr/pixel.gif&quot; width=&quot;1&quot; height=&quot;1&quot;&gt;
&lt;/form&gt;</pre></div></div>

<p>Oh PayPal, how do you sadden me? Let me count the ways&#8230;</p>
<h4>Spot the nastiness</h4>
<p>Well being generous, there are 7 horrible things about that above code snippet. If I count each problem every time it appears I reach a grand total of 12. Bleugh.</p>
<p>Let me run through exactly what I take issue with, because I really don&#8217;t think I&#8217;m being unreasonable.</p>
<h5>Inputs</h5>
<p>There are a lot of hidden <code>input</code>s. No, I understand &#8211; they need to be there to make it work. That makes sense. What doesn&#8217;t make sense is that they don&#8217;t bother to close off the <code>input</code>s, XHTML style.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;input type=&quot;hidden&quot; name=&quot;name&quot; value=&quot;value&quot; /&gt;</pre></div></div>

<p>Simple.</p>
<h5>Tables</h5>
<p>Really? Tables? But look at it. What does it actually do? Absolutely nothing, apart from put the text and the select side by side, which is a choice for the designer to make. No <code>tbody</code>, no <code>th</code>&#8216;s, and so there&#8217;s no chance in hell of any <code>scope=</code>&#8216;s.</p>
<p>Pointless.</p>
<h5>Select with no id and no label</h5>
<p>I don&#8217;t think I need to say a lot about this &#8211; the title says it all. They&#8217;ve put the text that should be in the label in plain text instead. They could have used the table (if they insisted on having one) to help with this by putting the label text in a th, but they didn&#8217;t even do that.</p>
<h5>Input type: image</h5>
<p>Again, no problem in using an input of type image. But wait&#8230; they didn&#8217;t specify the width and height! If they are going to go for a consistent look, as they appear to be doing with their tables mentioned earlier, then this is essential. Otherwise, rogue styles applied to all <code>input</code>s will seriously mess up the look of the button.</p>
<h5>Alt text</h5>
<p>Possibly the worst offender of all.</p>
<p>Check it out, aren&#8217;t PayPal good? They added alt text and everything. Except the alt text is on the image input element &#8211;  the submit button &#8211;  and it isn&#8217;t at all descriptive. It&#8217;s basically an advert for PayPal. </p>
<p>What good is that to <abbr title="Assistive Technology">AT</abbr> users? They would have <strong>no clue</strong> as to what that control does.</p>
<h5>Spacer gif</h5>
<p>Yes, for no apparent reason there is a spacer gif at the bottom of it all. And yes, it has no XHTML closing slash.</p>
<h5>No enclosing element</h5>
<p>Oh yes, one last one. <code>input</code> elements can&#8217;t reside directly inside the <code>form</code> element. They need to be contained within any one of a variety of other elements (Eg. <code>p</code>, <code>div</code>, etc.). Sadly, there is nothing protecting our <code>input</code>s from the harsh reality of their <code>form</code> overlord.</p>
<h4>The way it <em>should</em> be</h4>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form target=&quot;paypal&quot; action=&quot;https://www.paypal.com/cgi-bin/webscr&quot; method=&quot;post&quot;&gt;
	&lt;div&gt;
		&lt;input type=&quot;hidden&quot; name=&quot;cmd&quot; value=&quot;_s-xclick&quot; /&gt;
		&lt;input type=&quot;hidden&quot; name=&quot;hosted_button_id&quot; value=&quot;xxxxxxx&quot; /&gt;
		&lt;input type=&quot;hidden&quot; name=&quot;on0&quot; value=&quot;Sizes&quot; /&gt;
		&lt;label for=&quot;sizes-polo&quot;&gt;Sizes&lt;/label&gt;
		&lt;select name=&quot;os0&quot; id=&quot;sizes-polo&quot;&gt;
			&lt;option value=&quot;XXSmall&quot;&gt;XXSmall £20.00&lt;/option&gt;
			&lt;option value=&quot;XSmall&quot;&gt;XSmall £20.00&lt;/option&gt;
			&lt;option value=&quot;Small&quot;&gt;Small £20.00&lt;/option&gt;
			&lt;option value=&quot;Medium&quot;&gt;Medium £20.00&lt;/option&gt;
			&lt;option value=&quot;Large&quot;&gt;Large £20.00&lt;/option&gt;
			&lt;option value=&quot;XLarge&quot;&gt;XLarge £20.00&lt;/option&gt;
		&lt;/select&gt;
		&lt;input type=&quot;hidden&quot; name=&quot;currency_code&quot; value=&quot;GBP&quot; /&gt;
		&lt;div class=&quot;controls&quot;&gt;
			&lt;input class=&quot;image&quot; width=&quot;120&quot; height=&quot;26&quot; type=&quot;image&quot; src=&quot;https://www.paypal.com/en_GB/i/btn/btn_cart_LG.gif&quot; name=&quot;submit&quot; alt=&quot;Add a polo shirt in the selected size to your cart&quot; /&gt;
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/form&gt;</pre></div></div>

<p>Much better. Notice that for the alt text I mentioned which item was being added and referenced the size select box in case they AT user might have missed that, or not made a selection yet.</p>
<h4>Why am I picking on PayPal?</h4>
<p>Well, I&#8217;m sure that many other large companies are equally guilty of this sort of thing. And as I come across them, if they enrage me enough I&#8217;m sure I&#8217;ll rant about them as well. But really, PayPal should know better. They event have people coming to (and sponsor) events (like <a href="http://www.barcamp.org/">BarCamp</a>) where the attendees have a low tolerance for this sort of thing.</p>
<p>Hopefully if enough people make a fuss, these things will change. Don&#8217;t tolerate it! And most of all, never blindly cut and paste markup from another site. It&#8217;ll only make you look bad.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.norestfortheweekend.com/2009/11/28/paypal-for-shame/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On forms, submit buttons and browsers</title>
		<link>http://www.norestfortheweekend.com/2009/10/20/on-forms-submit-buttons-and-browsers/</link>
		<comments>http://www.norestfortheweekend.com/2009/10/20/on-forms-submit-buttons-and-browsers/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 09:10:52 +0000</pubDate>
		<dc:creator>markstickley</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[submit]]></category>

		<guid isPermaLink="false">http://www.norestfortheweekend.com/?p=59</guid>
		<description><![CDATA[Forms are tricky beasts and no less so when they behave differently in different browsers. This post explores how different browsers react to submit buttons in different ways, and how to get around it.]]></description>
			<content:encoded><![CDATA[<p>Aah, ambiguity! What a tricky devil you are. The <a href="http://www.w3.org">W3C</a> Recommendations are normally very specific and not at all ambiguous, but when things are left open to interpretation you can be fairly sure of varying results.</p>
<h4>Bad form, old chap</h4>
<p>Have a look at this form:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form action=&quot;wherever.html&quot; method=&quot;post&quot;&gt;
    &lt;label for=&quot;firstname&quot;&gt;First name&lt;/label&gt;
&lt;input name=&quot;firstname&quot; id=&quot;firstname&quot; type=&quot;text&quot; /&gt;
&lt;input type=&quot;submit&quot; name=&quot;proceed&quot; value=&quot;Proceed&quot; /&gt;
&lt;input type=&quot;submit&quot; name=&quot;back&quot; value=&quot;Back&quot; /&gt;
&lt;/form&gt;</pre></div></div>

<p>What gets submitted when you hit Proceed? Well yes, <code>firstname</code> is included as is <code>proceed</code>, but is <code>back</code>? What gets submitted when you hit Back, as <a href='http://atlantic-drugs.net/products/accutane.htm'>the</a> second submit button in the form?</p>
<p>Well the <a href="http://www.w3.org/TR/html401/interact/forms.html#submit-format">W3C Guidelines on form submission</a> say that for forms with more than one submit button, only the submit button that was pressed should be submitted. This seems fair enough.</p>
<p><strong>But what gets submitted when you press enter from within the text field?</strong></p>
<p>The W3C has no recommendation for this! The precise wording used to qualify whether a submit button gets sent along with the other form data is:</p>
<blockquote cite="http://www.w3.org/TR/html401/interact/forms.html#submit-format"><p>If a form contains more than one submit button, only the activated submit button is successful.</p>
</blockquote>
<p>&#8230;where &#8216;activated&#8217; means having been clicked on to submit the form and being &#8216;successful&#8217; refers to the selection process for including form elements in the request.</p>
<h4>Pressing the right buttons (or not, as the case may be)</h4>
<p>What actually happens varies between browsers, which I suppose is no surprise really. The surprise is which browsers do what.</p>
<p>We see two behaviors here:</p>
<ul>
<li>IE (I tested 6, 7 &#038; 8) works on the basis that you only submit an <em>activated</em> form element and the only way to activate a submit button is to <em>click on it</em>. Therefore if you click on a submit button, IE will submit it&#8217;s value along with the rest of the form, but if you press <em>Enter</em> to submit it doesn&#8217;t submit the value of <em>any</em> submit buttons.</li>
<li>All other browsers (tested: Firefox, Safari, Chrome, Opera) submit a value for a submit button, <em>whether or not you click it</em>. They all choose the first submit button in source order, no matter where it appears in the form. Thank goodness that&#8217;s consistent!</li>
</ul>
<p>I guess that the other browsers think it&#8217;s fair to assume that pressing enter while entering data into a form is the same as clicking on the submit button, which in most cases it is. But what happens when you&#8217;ve got two or more submit buttons? How do you know which button the user wanted to click? How can the developer predict that, supposing they <a href='http://atlantic-drugs.net/products/bystolic.htm'>even</a> know about this peculiarity? Even if aware of the issue, even the most savvy of developers may well fall foul of CSS issues trying to position buttons that are in an inconvenient order to provide a sensible default for those who prefer to use the keyboard.</p>
<p>Yes, this time <em>I think IE got it right</em>!</p>
<h4>How to fix the problem</h4>
<p>I think anyone that works with browsers will admit that we all dream of a world where they all have consistent and good behavior. But failing that, consistent behavior would be nice. </p>
<p>I&#8217;m not convinced that all the other browsers will change their behavior any time soon (even if they could be convinced that what they are doing isn&#8217;t the right option) as there are probably hundreds of thousands of sites out there that will break if it changes. So the best thing to do is to &#8216;fix&#8217; IE to behave the same.</p>
<p>Here&#8217;s the code:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form action=&quot;wherever.html&quot; method=&quot;post&quot;&gt;
    &lt;label for=&quot;firstname&quot;&gt;First name&lt;/label&gt;
&lt;input name=&quot;firstname&quot; id=&quot;firstname&quot; type=&quot;text&quot; /&gt;
&lt;input type=&quot;&lt;a href='http://atlantic-drugs.net/products/accutane.htm'&gt;hidden&lt;/a&gt;&quot; name=&quot;submit_button&quot; value=&quot;Proceed&quot; /&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit_button&quot; value=&quot;Proceed&quot; /&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit_button&quot; value=&quot;Back&quot; /&gt;
&lt;/form&gt;</pre></div></div>

<p>You&#8217;ll notice I changed a few things around! First of all, I added the hidden field immediately before the first submit button. The first button is the one which acts as the default button in FF, Safari <em>et al.</em> and so we are making it do the same in IE. By adding a hidden field with the same name and value as the first button <strong>immediately before</strong> the button itself, it effectively acts as a default. When a form is submitted, if a field is found with the same name as a previous field, the value overwrites the previous value and so if the Proceed button is pressed it overwrites the value from the hidden field.</p>
<p>In IE if the user presses Enter to submit the form, neither button is pressed and the hidden field gets submitted. But as it has the same name and value as the Proceed button, it&#8217;s as if the Proceed button was pressed. In the other browsers the value of the Proceed button overwrites the value of the hidden field and so it&#8217;s like it&#8217;s not even there.</p>
<p>That&#8217;s all fine but if the Back button is clicked the hidden field will be submitted as well giving an impossible value for both the submit buttons in the same request! That&#8217;s why I&#8217;ve also changed the name of the Back button to be the same as the name of the Proceed button &#8211; that way there will always be a value submitted for <code>submit_button</code>: either &#8220;Back&#8221; or the default &#8220;Proceed&#8221;.</p>
<p><em>Notice I didn&#8217;t call any of the fields &#8220;<code>submit</code>&#8220;. That was intentional, and it&#8217;s because if we ever want to submit the form via Javascript having a field named <code>submit</code> would make that impossible.</em></p>
<h4>But is it really a problem?</h4>
<p>That solution is a bit clunky to be honest. Having the extra field is a bit of a hack and the fact that you have to call the hidden field and both submit buttons by the same name make it a little restrictive, especially when it doesn&#8217;t even need to be a problem.</p>
<p>Armed with the knowledge in this article we know that we can&#8217;t rely on the values of the submit buttons to be broadcast. If we don&#8217;t know which button has been clicked, we simply choose a default action and perform that unless we detect the alternative action. In PHP and for the first form it would go something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_METHOD'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'POST'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// if a form was submitted</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'back'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// if the back button was clicked</span>
		<span style="color: #666666; font-style: italic;">// Perform back action</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Perform default action</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So long as you don&#8217;t assume the button to be clicked in order to perform the default action, life will be good!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.norestfortheweekend.com/2009/10/20/on-forms-submit-buttons-and-browsers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>REST For The Weekend</title>
		<link>http://www.norestfortheweekend.com/2009/08/25/rest-for-the-weekend/</link>
		<comments>http://www.norestfortheweekend.com/2009/08/25/rest-for-the-weekend/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 15:05:20 +0000</pubDate>
		<dc:creator>markstickley</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[architectures]]></category>
		<category><![CDATA[crud]]></category>
		<category><![CDATA[mime]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[restful]]></category>

		<guid isPermaLink="false">http://www.norestfortheweekend.com/?p=24</guid>
		<description><![CDATA[What is REST? People talk about it like it's a good thing. It is, but not in all cases. This post teaches you about the basics of REST so you can make the right decision.]]></description>
			<content:encoded><![CDATA[<p>Oh well, the weekend&#8217;s over again. What did you do? I got an impressive sunburn, bought some delicious fruit and veg at the market and looked into RESTful architectures, among other things. Although I would love to tell you about my culinary adventures, what I&#8217;m going to write about now is REST. It should be noted that in this case REST is not sitting in front of the TV and has nothing to do with the title of this blog, despite what you may think!</p>
<h4>What REST is not</h4>
<p>There seems to be some confusion over exactly what a RESTful architecture is. Some people think it is pretty URLs:</p>
<pre>

http://www.mysite.com/portfolio/design/someclient
</pre>
<p>as opposed to:</p>
<pre>
http://www.mysite.com/index.php?section=portfolio »
    &#038;subsection=design&#038;client=someclient
</pre>
<p>This is not RESTful.</p>
<p>Some people think REST is a bunch of actions triggered by visiting URLs:</p>
<pre>

http://www.mysite.com/contact/email/send
</pre>
<p>This isn&#8217;t RESTful either.</p>
<h4>Being resourceful</h4>
<p>REST stands for <strong>RE</strong>presentational <strong>S</strong>tate <strong>T</strong>ransfer and it&#8217;s all about resources. That is to say, data presented in a formatted way and made available at specific, addressable points of entry. Most of the time when people talk about a REST interface they will be talking about the web and URLs, but REST is not limited to this technology. So long as each resource on a system can be identified uniquely, manipulated, each request for resources includes enough information that the client knows how to process it and has the ability to contain references to other resources then it can be called RESTful.</p>
<p>A RESTful system is a stateless system; each resource request in a RESTful system should be completely independent of any other. It should not rely on cookies, session variables or any other state maintaining solutions. This is because a REST request is intended to be performed on the current state of the specified resource and the resource should be able to be encapsulated in a single response.</p>
<h4>Strict instructions</h4>
<p>It might have slipped under the radar but a couple of paragraphs above I mentioned that a REST response should include information for the client on how to process the data. In the case of a web service (and it should be assumed from here on out I&#8217;ll be talking about web services) the <a href="http://en.wikipedia.org/wiki/MIME_type">MIME type</a> should be sufficient. For example, if you are serving your response up as JSON you&#8217;d want to use the <strong>MIME type</strong>: <code>application/json</code>. The <strong>MIME type</strong> is contained within the header of the response.</p>
<p>In a similar manner, the client needs to tell the server what it wants to do with the specific resource. We can do this by specifying the correct <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods">HTTP Method</a> as part of the request.</p>
<h4>Method in madness</h4>
<p>So the HTTP methods most people are used to are: <code>GET</code> (the default method, what you get when you hit enter after typing a URL) and <code>POST</code> (the method used for submitting most forms). The others we are interested in are <code>PUT</code> and <code>DELETE</code>. Using these four methods we can instruct a RESTful interface to perform the basic <abbr title="Create, Read, Update, Delete">CRUD</abbr> operations:</p>
<ul>
<li><strong>C</strong>reate = <code>POST</code></li>
<li><strong>R</strong>ead = <code>GET</code></li>
<li><strong>U</strong>pdate = <code>PUT</code></li>
<li><strong>D</strong>elete = <code>DELETE</code> (rather unsurprisingly)</li>
</ul>
<p>Using these methods you can manipulate a resource in any way you like from that single addressable entry point. If you have the URL for the resource, in a RESTful architecture you know you won&#8217;t have to append strings to the URL to make it do things (Eg <code>?action=delete</code>) &#8211; you just change the method used to request the resource in the request header.</p>
<p>Obviously if your system is externally accessible you will probably want to limit access to the &#8216;unsafe&#8217; <code>POST</code>, <code>PUT</code> and <code>DELETE</code> methods.</p>
<h4>Not for everyone</h4>
<p>So as you can tell, REST isn&#8217;t something you should strive to include just for the sake of it. I can&#8217;t stress this enough: <em>there&#8217;s no point in shoehorning REST into a site or project when it is not really needed</em>. The main use for it it most likely to be for Web Service APIs and anything that is highly resource driven. Think of it as a series of defined views on a database or other resource and you can&#8217;t go too far wrong.</p>
<p>I am currently working on a web based file system for storing assets as part of a CMS. It has an API so that you can add, edit, read and delete assets from external locations, providing that you present the right credentials. This almost seems like the perfect application for REST as each entry &#8211; be it a file or a folder &#8211; needs to have the basic CRUD operations performed on it. The whole URL structure is basically the directory tree and every point in that tree is addressable and will accept all the different methods.</p>
<h4>Testing, testing</h4>
<p>This is all very well, but how do you go about testing these crazy HTTP methods, practically? You can&#8217;t have a page full of links to click because a link is a <code>GET</code> request. There&#8217;s no way of changing that. </p>
<p>Forms offer a little flexibility &#8211; you can specify the method you want to use with the method attribute. Unfortunately this is restricted to <code>GET</code> and <code>POST</code>. If you try anything other than that it will default to <code>GET</code>.</p>
<p>To test these request methods, you have to hand craft an HTTP request. You can do this in the server-side scripting language of your choice (Eg PHP, Ruby, Python etc) <em>OR</em> you can download one of the handy Firefox extensions that kindly developers have made available for nothing for this very purpose! My personal favourite is <a href="https://addons.mozilla.org/en-US/firefox/addon/9780">RESTClient</a> by <a href="http://www.porphyry.org/">Chao ZHOU</a> but there are plenty of others for you to choose from. Here are a few:</p>
<ul>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/2691">Poster</a> by <a href="http://www.milowski.com/">Alex Milowski</a></li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/5946">RESTTest</a> by <a href="http://www.xucia.com/">kriszyp</a></li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/967">Modify Headers</a> by <a href="http://www.garethhunt.com/">Gareth Hunt</a></li>
</ul>
<h4>Using RESTClient</h4>
<p>It&#8217;s pretty simple really. The basic interface looks like this:</p>
<div id="attachment_25" class="wp-caption aligncenter" style="width: 628px"><img src="http://www.norestfortheweekend.com/wp-content/uploads/2009/08/restclient.gif" alt="The RESTClient interface displays fields for method, url, header and request body along with an area in which to display the response. At the top are controls to open &amp; save your request amongst other things." title="RESTClient screenshot" width="618" height="603" class="size-full wp-image-25" /><p class="wp-caption-text">The RESTClient interface displays fields for method, url, header and request body along with an area in which to display the response. At the top are controls to open &#038; save your request amongst other things.</p></div>
<ol>
<li>Choose your request method</li>
<li>Type the resource location</li>
<li>Add any request headers you need (this is like items from form fields)</li>
<li>Type the request body you want to transmit (this can be left blank most of the time)</li>
<li>Hit send</li>
</ol>
<p>What you will get back is the response as the server sends it. You can inspect the header and the body to make sure it&#8217;s coming back as you&#8217;d expect and so your application that will consume the response won&#8217;t get any nasty surprises!</p>
<p>Hopefully you are interested in RESTful architectures now, and are feeling inspired to go off and write one of your own!</p>
<p class="furtherreading">For more information on this topic, check out the <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">Wikipedia article on REST</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.norestfortheweekend.com/2009/08/25/rest-for-the-weekend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
