<?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>a pint of javascript (and general web stuff) &#187; css</title>
	<atom:link href="http://blog.gonchuki.com/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.gonchuki.com</link>
	<description></description>
	<lastBuildDate>Tue, 06 Jul 2010 21:45:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Standards Compliancy is a lie (or, how all browsers have a broken border-radius)</title>
		<link>http://blog.gonchuki.com/archives/standards-compliancy-is-a-lie-or-how-all-browsers-have-a-broken-border-radius/</link>
		<comments>http://blog.gonchuki.com/archives/standards-compliancy-is-a-lie-or-how-all-browsers-have-a-broken-border-radius/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 16:56:25 +0000</pubDate>
		<dc:creator>gonchuki</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://blog.gonchuki.com/?p=170</guid>
		<description><![CDATA[Day after day we see a new release from one of the major internet browser developers boasting how they comply with web standards and how they are targeting a gazillion of experimental features that no one cares about (I bet only 3% of web developers cared to study the bible of -webkit prefixes), yet except [...]]]></description>
			<content:encoded><![CDATA[<p>Day after day we see a new release from one of the major internet browser developers boasting how they comply with web standards and how they are targeting a gazillion of experimental features that no one cares about (I bet only 3% of web developers cared to study the bible of -webkit prefixes), yet except for Firefox* all of them get border-radius completely wrong (Firefox actually has a minor annoyance but it&#039;s bearable). Can you say you are standards-compliant if you have a broken implementation?<br />
<span id="more-170"></span></p>
<h3 class="section">a little back story</h3>
<p>A few months ago, the <a href="http://blogs.msdn.com/b/ie/archive/2010/03/19/the-css-corner-about-css-corners.aspx"><acronym title="Internet Explorer">IE</acronym> Blog showcased some IE9 goodness</a> and made a call to action for better border-radius implementations. They rightfully shown how they are getting it right this time, and how most other browsers out there are broken, with Safari/Chrome (Webkit) being the worst still at the time of writing this article. But not everything in their implementation is correct, IE9 pre 3 still exhibits the same issue as the other browsers that I&#039;m presenting today.</p>
<h3 class="section">the big bug theory</h3>
<p>So what&#039;s the issue with border-radius? simple answer: the background color bleeds behind the radius when you also have a border in the same element.<br />
Let&#039;s first use a real world example of a live site that paradoxically exposes the bug: <a href="http://playground.html5rocks.com/">HTML5 Rocks Playground</a></p>
<div class="center"><img src="http://sandbox.gonchuki.com/border-radius/chrome5-firefox.png" alt="Chrome 5 vs. Firefox" /><span class="caption">Chrome 5.0.375.99 on the left, Firefox 3.6.6 on the right, Windows 7 with ATI X300</span></div>
<p><strong>See the blue garbage on the rounded corner?</strong> that&#039;s what most browsers do.</p>
<p>Now, to rule out a possible specific software/hardware combination, I went thru several test machines and browsers to see if the bug was repeatable:</p>
<div class="center showcase_img">
<img src="http://sandbox.gonchuki.com/border-radius/fx_366_winxp_ati4850.png" alt="" /><img src="http://sandbox.gonchuki.com/border-radius/chrome_5_winxp_ati4850.png" alt="" /><img src="http://sandbox.gonchuki.com/border-radius/opera_1060_winxp_ati4850.png" alt="" /><img src="http://sandbox.gonchuki.com/border-radius/chrome_5_ubuntu_vbox.png" alt="" /><img src="http://sandbox.gonchuki.com/border-radius/ie_9pre3_win7_intel.png" alt="" /><img src="http://sandbox.gonchuki.com/border-radius/chrome_6_winxp_8600.png" alt="" /><img src="http://sandbox.gonchuki.com/border-radius/chrome_6_win7_intel.png" alt="" /><img src="http://sandbox.gonchuki.com/border-radius/safari_5_winxp_ati.png" alt="" />
</div>
<p></p>
<h3 class="section">reproducing the bug</h3>
<p>So how hard is to reproduce the bug? sadly, not at all. Here&#039;s the base recipe for disaster:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#999</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#f00</span><span style="color: #00AA00;">;</span>
border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span></pre></td></tr></table></div>

<style type="text/css">
div.border-radius-box {
border: 3px solid #999; background-color: #f80; float: left; width: 60px; height: 60px; margin: 0 7px;
}
div.box-2  { background-color: #0fa; -moz-border-radius: 5px;-webkit-border-radius: 5px; border-radius: 5px; }
div.box-3  { background-color: #f3a; -moz-border-radius: 10px;-webkit-border-radius: 10px; border-radius: 10px; }
div.box-4  { background-color: #1a0; -moz-border-radius: 15px;-webkit-border-radius: 15px; border-radius: 15px; }
div.box-5  { background-color: #07f;  -moz-border-radius: 20px;-webkit-border-radius: 20px; border-radius: 20px;}
div.box-6  { background-color: #f00;  -moz-border-radius: 25px;-webkit-border-radius: 25px; border-radius: 25px; }
div.box-7  { background-color: #377;  -moz-border-radius: 30px;-webkit-border-radius: 30px; border-radius: 30px; }
div.box-outer  { background-color: #999; padding: 3px; border: 0 none; }
div.box-inner  { border: 0 none; margin: 0; -moz-border-radius: 23px;-webkit-border-radius: 23px; border-radius: 23px;  }
.showcase_img img { margin: 5px 10px; border: 1px solid #ddd; }
</style>
<div class="border-radius-box"></div>
<div class="border-radius-box box-2"></div>
<div class="border-radius-box box-3"></div>
<div class="border-radius-box box-4"></div>
<div class="border-radius-box box-5"></div>
<div class="border-radius-box box-6"></div>
<div class="border-radius-box box-7"></div>
<p><br style="clear: left;" /><br />
zooming-in the issue:</p>
<div class="center"><img src="http://sandbox.gonchuki.com/border-radius/fx_366_demo.png" alt="" /><span class="caption">Firefox 3.6.6</span></div>
<p></p>
<div class="center"><img src="http://sandbox.gonchuki.com/border-radius/chrome_5_demo.png" alt="" /><span class="caption">Chrome 5</span></div>
<p></p>
<div class="center"><img src="http://sandbox.gonchuki.com/border-radius/opera_1060_demo.png" alt="" /><span class="caption">Opera 10.60</span></div>
<p></p>
<div class="center"><img src="http://sandbox.gonchuki.com/border-radius/ie_9pre3_demo.png" alt="" /><span class="caption">IE9 pre 3</span></div>
<p>given the previous example and screenshots, you might have noticed the other issue: <strong>Firefox is not actually bug-free.</strong> It has a slight issue blending the element background with the border. it&#039;s not as bad as the bleeding issue, but it&#039;s still annoying. Also from the previous set and this one, we notice how the IE9 and Opera 10.60 implementations are an order of magnitude better than what Webkit achieves.</p>
<h3 class="section">finding a work-around</h3>
<p>As you might have guessed, the only reliable work-around to date is nesting rounded elements when you need a distinctly colored border. Using padding on the outer box equal to the border-width required does the trick and works across all browsers:</p>
<div class="border-radius-box box-6 box-outer">
<div class="border-radius-box box-6 box-inner"></div>
</div>
<p>Of course it&#039;s not all fun and games, <strong>you need to specify a different border-radius for the inner box</strong> as they both have different sizes. In this case, the outer box has 25px while the inner one has 23px.<br style="clear: left;" /></p>
<p><strong>Can we stop with the pain already?</strong> How many years have passed since the first border-radius implementation and they are still getting it wrong?<br />
this is how I feel about the current state of border-radius:</p>
<div class="center"><img src="http://sandbox.gonchuki.com/border-radius/doin_it_wrong.jpg" alt="" /></div>
<p><strong>Can every browser get it right before boring us once again with their endless speech on how shiny and compliant they are?</strong> It&#039;s not <a href="http://farscape.wikia.com/wiki/Frell">frelling</a> rocket science.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.gonchuki.com/archives/standards-compliancy-is-a-lie-or-how-all-browsers-have-a-broken-border-radius/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>CSS Sprites2 &#8211; It&#039;s MooTools Time</title>
		<link>http://blog.gonchuki.com/archives/css-sprites2-its-mootools-time/</link>
		<comments>http://blog.gonchuki.com/archives/css-sprites2-its-mootools-time/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 17:29:20 +0000</pubDate>
		<dc:creator>gonchuki</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[sprites]]></category>

		<guid isPermaLink="false">http://blog.gonchuki.com/?p=34</guid>
		<description><![CDATA[A few months ago you may have read Dave Shea&#039;s entry on A List Apart &#034;CSS Sprites2 &#8211; It&#039;s JavaScript Time&#034; where he implemented a variant of his own CSS Sprites article by adding jQuery based animations. In this same article Dave encouraged us [developers] to port it to other libraries, so after a few [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago you may have read <a href="http://www.mezzoblue.com/">Dave Shea</a>&#039;s entry on A List Apart &#034;<a href="http://www.alistapart.com/articles/sprites2"><acronym title="Cascading Style Sheets">CSS</acronym> Sprites2 &#8211; It&#039;s JavaScript Time</a>&#034; where he implemented a variant of his own <a href="http://www.alistapart.com/articles/sprites"><acronym title="Cascading Style Sheets">CSS</acronym> Sprites</a> article by adding <a href="http://jquery.com">jQuery</a> based animations. In this same article Dave encouraged us [developers] to port it to other libraries, so after a few months of inactivity I&#039;m back with the <a href="http://mootools.net">MooTools</a> port of this slick effect.<br />
<span id="more-34"></span></p>
<link rel="stylesheet" type="text/css" href="http://sandbox.gonchuki.com/sprites2/sprites2.css" media="all" />
<h3 class="section">Enter the MooTools</h3>
<p>While the original version used jQuery (1.2.6 at that time) and lots of people like it, we (mootoolers) have a different approach to code specially emphasizing on OOP techniques and readability. Part of the issue might not be jQuery per-se and be Dave&#039;s code that was a little obfuscated, but it anyways has a lot of room for improvement.<br />
This article will just describe differences between the MooTools implementation and the Dave&#039;s jQuery one, so unless stated otherwise, everything from the ALA article applies here.</p>
<h3 class="section">enter the Sprites2 class</h3>
<p>Part of the requirements I imposed myself when porting to MooTools was that it had to be easier to use than the jQuery version, and that it should give a certain degree of flexibility to extend the possible transition effects.<br />
End result is a class intuitively named Sprites2, where you gracefully pass named parameters:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> Sprites2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>mode<span style="color: #339933;">:</span> <span style="color: #3366CC;">'fade'</span><span style="color: #339933;">,</span> item_selector<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ul.nav a'</span><span style="color: #339933;">,</span> duration<span style="color: #339933;">:</span> <span style="color: #CC0000;">250</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

Now that&#039;s classy! [stupid pun, I know]<br />
Notice that these parameters above are the class defaults, so you could have just as easily used <var>new Sprites2();</var> and the end result would be the same.</p>
<h3 class="section">changes to original code and idea</h3>
<p>Apart from moving the code to a class, a change to note is the removal of the :active state from the <acronym title="Cascading Style Sheets">CSS</acronym> and the <var>setActive</var> parameter in the <acronym title="JavaScript">JS</acronym> code. This was mostly a personal preference as the :active pseudo-class created a few issues when holding the mouse on the element and releasing outside of it. Other notable changes in the <acronym title="Cascading Style Sheets">CSS</acronym> are the simplification of the implementation/adaptation process by using a simpler approach on the styles (for example, using <var>height:100%;</var> where applicable instead of <a href="http://www.alistapart.com/d/sprites2/examples/example-script.css">redefining height:48px; 5 times in the <acronym title="Cascading Style Sheets">CSS</acronym></a>).</p>
<p>MooTools also has a free &#034;upgrade&#034; built-in: animations have an internal state so that if you roll out from the element and enter it again, the transition will continue to run smoothly. In contrast, jQuery version (may be by code design, maybe because of a library limitation) flickers madly when you roll over and out of the element repeatedly with an interval less than the effect duration.</p>
<p>Also to note, and as mentioned, the Sprites2 class can be easily extended outside of the sprites2.js file with just a few lines of code to create for example a horizontal slide effect:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">Sprites2.<span style="color: #660066;">implement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  effects<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    slide_x<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>fx_element<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      fx_element.<span style="color: #660066;">store</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'width'</span><span style="color: #339933;">,</span> fx_element.<span style="color: #660066;">getSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setStyles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'width'</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">show_fn</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>fx_element<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> fx_element.<span style="color: #660066;">tween</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'width'</span><span style="color: #339933;">,</span> fx_element.<span style="color: #660066;">retrieve</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'width'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">hide_fn</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>fx_element<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> fx_element.<span style="color: #660066;">tween</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'width'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>and you can start using it right away with <var>new Sprites2({mode: &#039;slide_x&#039;});</var>. This obviously works any way you want, as you can manually add or remove the effects directly in the source file.</p>
<h3 class="section">download, full demo and requirements</h3>
<p>The example here is running on a standard <a href="http://ajax.googleapis.com/ajax/libs/mootools/1.2.1/mootools-yui-compressed.js">google hosted version of mootools 1.2.1</a>. For those of you that use custom builds, just be sure to add FX.Tween and FX.Morph to your standard array of includes (morph is only used by the &#034;animate&#034; effect, so if you don&#039;t use that one you can exclude it.)</p>
<p><a href="http://sandbox.gonchuki.com/sprites2/sprites2_moo.html">View full online demo</a></p>
<p><a href="http://sandbox.gonchuki.com/sprites2/sprites2.zip" rel="download" class="download">Download Sprites2</a> for MooTools [zip].</p>
<p><strong>new!</strong> &#8211; by popular demand (not really), I have just set-up a git repo so you can fork the latest source: <a href="http://github.com/gonchuki/sprites2-moo">http://github.com/gonchuki/sprites2-moo</a></p>
<p><strong>License:</strong> <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a><br />
<small>disclaimer: original code did not contain any license whatsoever (like all ALA code), so I assumed a CC share-alike license applies perfectly in this case.</small><br />]]></content:encoded>
			<wfw:commentRss>http://blog.gonchuki.com/archives/css-sprites2-its-mootools-time/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
	</channel>
</rss>
