<?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:georss="http://www.georss.org/georss" 
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>bioneural.net &#187; css</title>
	<atom:link href="http://www.bioneural.net/tag/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bioneural.net</link>
	<description>bioneural.net is for stuff worth sharing: commentary by Bruce McKenzie. Major topics covered are gadgets, informatics, Internet, Mac, mobile, musings, New Zealand, photography, Project Koru, quicklinks, rant, rave, travel and Windows</description>
	<pubDate>Thu, 08 May 2008 19:36:56 +0000</pubDate>
	
	<language>en</language>
	<image>
		<title>bioneural.net</title>
		<url>http://www.bioneural.net/images/kiwi-yellow-64px.png</url>
		<link>http://www.bioneural.net</link>
		<width>64</width>
		<height>64</height>
		<description>bioneural.net</description>
	</image>
		<item>
		<title>Web developer widgets</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F04%2F11%2Fweb-developer-widgets%2F&amp;seed_title=Web+developer+widgets</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F04%2F11%2Fweb-developer-widgets%2F&amp;seed_title=Web+developer+widgets#comments</comments>
		<pubDate>Fri, 11 Apr 2008 21:42:29 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Quicklinks]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[Mac]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/?p=917</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>Mac-based web developers may yet find a use for Dashboard. <a href="http://www.apple.com/downloads/dashboard/reference/seess.html" rel="external">SeeSS</a> is a CSS property reference detailing inheritance, CSS compliance, Safari support, possible and default values, examples, plus an informative description [<a href="http://www.bioneural.net/wp-content/uploads/2008/04/seess.jpg" rel="ibox">screenshot</a>]. <a href="http://www.apple.com/downloads/dashboard/developer/phpfunctionreference.html" rel="external">PHP Function Reference</a> provides offline access to the PHP manual, a cheat sheet, and an interactive date formatter [<a href="http://www.bioneural.net/wp-content/uploads/2008/04/phpfr.jpg" rel="ibox">screenshot</a>].</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F04%2F11%2Fweb-developer-widgets%2F&amp;seed_title=Web+developer+widgets/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>How to safely inject CSS3 using jQuery</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F14%2Fhow-to-safely-inject-css3-using-jquery%2F&amp;seed_title=How+to+safely+inject+CSS3+using+jQuery</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F14%2Fhow-to-safely-inject-css3-using-jquery%2F&amp;seed_title=How+to+safely+inject+CSS3+using+jQuery#comments</comments>
		<pubDate>Thu, 14 Feb 2008 14:14:56 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2008/02/14/how-to-safely-inject-css3-using-jquery/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>So you fancy using some of that &uuml;ber-cool draft CSS3 that <a href="http://webkit.org/" rel="external">WebKit</a> browsers can handle, such as text shadows, drop shadows, opacity and rounded corners? But at the same time you want to present only valid CSS to the W3C CSS <a href="http://jigsaw.w3.org/css-validator/" rel="external">Validator</a>? It's a dilemma, but it is possible to have your cake and eat it too&mdash;albeit by hiding CSS in JavaScript and thus cheating the Validator. However, there is even a precedent for doing so.<br />
<span id="more-829"></span></p>
<p>During the course of researching my review of the <a href="http://www.bioneural.net/2008/02/06/the-best-way-to-do-corners-and-gradients/">various</a> <a href="http://www.bioneural.net/2008/02/13/corners-gradients-and-shadows-with-jquery/">ways</a> to make rounded corners, drop shadows, and gradients I learned more about <a href="http://www.w3.org/TR/css3-roadmap/" rel="external">CSS3</a> and the <a href="http://jquery.com/" rel="external">jQuery</a> JavaScript library. They just needed introducing to one another.</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/effects.jpg" width="450" height="376" alt="effects.jpg"/><br /><span class="caption">Text shadows, drop shadows, and round corners in Safari 3</span></p>
<h4>A historical precedent</h4>
<p>The concept of tricking the Validator to pass CSS that is incorrectly implemented or proprietary and not part of the W3C spec is not new. Many web developers have found it necessary to employ various hacks in their CSS to accommodate differences in the way browsers interpret the rules. Others have used proprietary code to overcome limitations or quirks in the way some browsers handle certain content. For example, the following in your document head could be used to fix IE6's lack of handling for transparent PNGs and mis-handling of the box model, floats, overflow, <a href="http://www.bioneural.net/2008/02/01/ie6-italics-and-overflow-issues/">italics</a>, etc.:</p>
<pre><code>&lt;!--[if lte IE 6]&gt;
	&lt;style type="text/css"&gt;
	#pnglogo {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',src='../logo-trans.png'); padding-top: 57px; }
	&lt;/style&gt;
	&lt;link rel="stylesheet" type="text/css" media="screen" href="../ie6-patches.css" /&gt;
&lt;![endif]--&gt;</code></pre>
<p>It's a hack: there's no other term for it. In the above example we're using proprietary conditional comments and filters to fix proprietary cock-ups. Seems fair, doesn't it?</p>
<p>So, if we can hack our way to supporting inferior or out-dated browsers, why should we not also employ hacks to support leading-edge browsers like Safari 3 that are already capable of rendering much of that draft CSS3 goodness? </p>
<h4>Using jQuery's CSS injector</h4>
<p>There are probably multiple JavaScripts that let you load CSS via the <a href="http://www.w3.org/DOM/" rel="external">DOM</a>, but since I'm using jQuery anyway that's how I've chosen to do it. If you don't have jQuery installed go <a href="http://docs.jquery.com/Downloading_jQuery" rel="external">get</a> it and load it in your document head e.g.:</p>
<pre><code>&lt;script type="text/javascript" src="../jquery-1.2.3.pack.js"&gt;&lt;/script&gt;</code></pre>
<p>Below this we create a <code>$(document).ready()</code> <a href="http://docs.jquery.com/Events/ready#fn" rel="external">function</a> so that the contents load via the DOM and hopefully before the page content is displayed. Inside this function our "content" consists of a series of CSS <a href="http://docs.jquery.com/Selectors" rel="external">selectors</a> (inside the first bracket) paired with the CSS properties we wish to inject (name and value, comma-separated) joined via <a href="http://docs.jquery.com/CSS/css#namevalue" rel="external">.css</a>. Example:</p>
<pre><code>&lt;!-- Have jQuery inject WebKit CSS via DOM on selected elements --&gt;
&lt;script type="text/javascript"&gt;
	$(document).ready(function(){
	$("h1").css("text-shadow","black 0.2em 0.3em 0.2em");
	$(".description").css("text-shadow","black 0.2em 0.3em 0.2em");
	$("#page").css("-webkit-box-shadow","#333 0px 5px 10px");
	$("#footer").css("-webkit-box-shadow","#333 0px 5px 10px");
	$(".container").css("-webkit-box-shadow","#333 0px 5px 10px");
	$(".container").css("-webkit-border-radius","10px");
});
&lt;/script&gt;</code></pre>
<p>If you had a div with the class "container koru", for <a href="http://www.bioneural.net/category/project-koru/">example</a>, Safari 3 will blend the above box-shadow and border-radius styling (as inline CSS3) with any additional CSS2.1 styling for .container or .koru present in your stylesheet. You can see what's going on using that browser's <a href="http://webkit.org/blog/122/webkit-3-10-new-things/" rel="external">Web Inspector</a>:</p>
<p><img src='http://www.bioneural.net/wp-content/uploads/2008/02/s3-inspector.jpg' alt='web-inspector' /></p>
<p class="info"><em>Note</em>: A -webkit- or -moz- prefix on CSS properties is used respectively by the Safari and Mozilla/Firefox browsers to indicate tentative support for as yet non-ratified web standards. Thus <code>-webkit-border-radius: 10px;</code> and <code>-moz-border-radius: 10px;</code> are both potentially differing implementations of "<a href="http://www.w3.org/TR/2005/WD-css3-background-20050216/#the-border-radius" rel="external">border-radius</a>".</p>
<p>OK, so the "how" is easy. Now the "Should you?"</p>
<h4>The positives</h4>
<p class="for">Effects are rendered without requiring images.</p>
<p class="for">Effects are rendered without requiring add-on JavaScript effects libraries.</p>
<p class="for">Effects are rendered without increasing page size or load time.</p>
<p class="for">Effects are rendered that may be impossible with some JavaScript or image-based techniques (e.g. anti-aliasing, liquid layout support).</p>
<p class="for">Effects can be targeted at specific web browser engines.</p>
<p class="for">No changes to semantic mark-up are required.</p>
<p class="for">Your stylesheets remain W3C-valid (if they were before!).</p>
<p class="for">Browsers simply ignore CSS properties they don't understand, so degradation is graceful.</p>
<p class="for">If JavaScript is disabled browsers will still load your stylesheets, so degradation is graceful.</p>
<p class="for">It is compatible with template-based websites in not requiring page-specific effects scripts to be inserted into mark-up.</p>
<p class="for">When the -webkit- or -moz- prefix gives way to the real deal of W3C-ratified CSS3 we can simply remove the script and move the content to our stylesheet without having to re-design effects elements or edit any mark-up.</p>
<p class="for">If you don't start using CSS3 now you might have retired before it becomes W3C-ratified.</p>
<h4>The negatives</h4>
<p class="against">Turning off your stylesheet does not disable styling loaded via the DOM.</p>
<p class="against">Effects can be targeted at specific web browser engines (like browser-targeting, a double-edged sword that undermines the uniformity of the "web experience").</p>
<p class="against">It could be construed as cheating. It is.</p>
<p>What are your views, if you have any, on the merits or otherwise of this technique?</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F14%2Fhow-to-safely-inject-css3-using-jquery%2F&amp;seed_title=How+to+safely+inject+CSS3+using+jQuery/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Corners, gradients and shadows with jQuery</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F13%2Fcorners-gradients-and-shadows-with-jquery%2F&amp;seed_title=Corners%2C+gradients+and+shadows+with+jQuery</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F13%2Fcorners-gradients-and-shadows-with-jquery%2F&amp;seed_title=Corners%2C+gradients+and+shadows+with+jQuery#comments</comments>
		<pubDate>Wed, 13 Feb 2008 15:36:40 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[webdev]]></category>

		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2008/02/13/corners-gradients-and-shadows-with-jquery/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>Previously we <a href="http://www.bioneural.net/2008/01/06/from-protoaculous-to-jquery/">looked</a> at moving to jQuery, and then at the best way to do corners and gradients using a variety of <a href="http://www.bioneural.net/2008/02/06/the-best-way-to-do-corners-and-gradients/">techniques</a> (Part 1). In this follow-on article (Part 2) I want to share how jQuery can be extended for similar cornering, gradient, and drop shadow visual effects. Although my JavaScript ability is not much beyond "cut and paste" the idea here is to share how easy it is to create these effects for other folk possessed by similar (in)ability.<br />
<span id="more-826"></span></p>
<h4>Situation recap</h4>
<p>In <a href="http://www.bioneural.net/2008/02/06/the-best-way-to-do-corners-and-gradients/">Part 1</a> we explored various ways to make rounded corners, comprising one or more of JavaScript, CSS, Flash, and SVG. Ditto for drop shadows. Implementing a gradient was restricted to the use of background (or inline) images, or to SVG. There are a few more tricks we might try for gradients:</p>
<ul>
<li>We could load a transparent PNG as a CSS background and vary the fill colour on the container to allow for a multitude of colour-graduated boxes without further image editing (see this ALA <a href="http://www.alistapart.com/articles/supereasyblendys" rel="external">article</a>);</li>
<li>Unfortunately the CSS 3 draft as of this writing doesn't include background gradients, but you might be able to fake it using <a href="http://www.css3.info/preview/colored-border/" rel="external">border-color</a>;</li>
<li>We could use JavaScript effects libraries.</li>
</ul>
<p>It turns out we can use JavaScript to create our corners and drop shadows too. There's also a <a href="http://blue-anvil.com/archives/anti-aliased-rounded-corners-with-jquery" rel="external">plugin</a> for using <a href="http://www.curvycorners.net/" rel="external">curvyCorners</a> with jQuery that more than halves the standalone curvyCorners code size.</p>
<h4>Extending jQuery</h4>
<p>While there are some basic <a href="http://docs.jquery.com/Effects" rel="external">effects</a> (hide, toggle, slide, etc.) and manipulation options in the jQuery core API, jQuery <a href="http://ui.jquery.com/" rel="external">UI</a> is a bolt-on library of interactive controls that deal with mouse interaction (e.g. resizing, dragging) and other "user interface" extensions. As of this writing the jQuery documentation is incomplete and the developers in the process of transitioning visual effects formerly included in jQuery UI to a new sister library called jQuery <a href="http://ui.jquery.com/enchant/" rel="external">Enchant</a>. The controls (also referred to as core interaction plugins, UI widgets, or components) are themselves are almost invariably dependent on other jQuery extensions&mdash;needing at least the <a href="http://jquery.com/plugins/project/dimensions" rel="external">Dimensions</a> plugin.</p>
<p>So jQuery needs to get its act together in respect of naming conventions, but perhaps this is more indicative of active development rather than lack of direction? I guess jQuery UI/ Enchant are to jQuery as <a href="http://script.aculo.us/" rel="external">script.aculo.us</a> is to <a href="http://prototypejs.org/" rel="external">Prototype</a>. In a nutshell we're saying that with some jQuery code that in turn requires a bit more extra code in order to work, in addition to the code that is "jQuery" itself&mdash;we can create visual elements like drop shadows! jQuery is thus readily extendible; to use these extra bits of code you just need to load the relevant add-on script in your document head, after having loaded jQuery itself. A picture may help:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/jquery.jpg" width="383" height="326" alt="jquery.jpg" /></p>
<h4>Test cases</h4>
<p>I've used the same basic test box from Part 1, so our core document structure looks like this:</p>
<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;title&gt;jQuery test cases&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;script type="text/javascript" src="jquery-1.2.3.pack.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="jquery.dimensions.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="jquery.corner.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="jquery.gradient.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="fx.shadow.js"&gt;&lt;/script&gt;
&lt;style type="text/css"&gt;
	...
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
// &lt;![CDATA[
	$(document).ready(function() {
	...
	});
// ]]&gt;
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class="className"&gt;
	&lt;h4&gt;Lorem ipsum&lt;/h4&gt;
	&lt;p&gt;Lorem ipsum dolor...&lt;/p&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>With all the necessary libraries loaded we can start adding effects to our div by calling them within <code>$(document).ready()</code> (in place of ... above).</p>
<p class="download">Download the test files <a href="http://www.bioneural.net/docs/jquery-tests.zip">here</a> (.zip archive, 27KB).</p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/jquery-tests/jquery-test.html">live</a> link.</p>
<h4>Case 1: Round corners</h4>
<p>If you wanted to use fancy images to produce round corners yet avoid extra mark-up, you could use <a href="http://15daysofjquery.com/wrap-it-up-pretty-corners/13/" rel="external">this</a> technique. Alternatively use no images at all via the jQuery corner plugin, available <a href="http://jqueryjs.googlecode.com/svn/trunk/plugins/corner/jquery.corner.js" rel="external">here</a>. The plugin supports a variety of corner types and borders as you can see in the <a href="http://malsup.com/jquery/corner/" rel="external">demos</a>. The following call will add cornering with a radius of 20px to a div with the class .cornered:</p>
<pre><code>$('div.cornered').corner("20px");</code></pre>
<p>This will have the following effect on our test box:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/rounded.jpg" width="265" height="346" alt="rounded.jpg" /></p>
<h4>Case 2: Gradients</h4>
<p>The Element gradient plugin, available <a href="http://plugins.jquery.com/project/elementgradient" rel="external">here</a>, will fill an element (e.g. div) with a linear gradient of specified direction (horizontal or vertical only) and opacity. It requires the <a href="http://plugins.jquery.com/project/dimensions/" rel="external">Dimensions</a> plugin. The following call will add a vertical gradient from black to white with 40% opacity to a div with the class .gradient:</p>
<pre><code>$('div.gradient').gradient({ topcolor: '#000000', bottomcolor: '#ffffff', horizontal: false, opacity: 40 });
</code></pre>
<p>This will have the following effect on our test box:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/gradient.jpg" width="262" height="344" alt="gradient.jpg" /></p>
<p>Note that you can't shorten the hex-code (it must be #ffffff not #fff for white, for example).</p>
<p class="info"><em>Tip</em>: If you leave the gradient as black to white with some opacity you can create colour gradients much more easily but changing only the background colour of the container. This is a jQuery version of the ALA super-easy blendy backgrounds <a href="http://www.alistapart.com/articles/supereasyblendys" rel="external">trick</a>.</p>
<h4>Case 3: Borders</h4>
<p>Back to the jQuery corner plugin; it can also do borders using nested elements i.e. one rounded box inside another. So our mark-up could be edited thus:</p>
<pre><code>&lt;div class="xtra"&gt;
&lt;div class="border"&gt;
	&lt;h4&gt;Lorem ipsum&lt;/h4&gt;
	&lt;p&gt;Lorem ipsum dolor...&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</code></pre>
<p>But we don't want to edit our mark-up do we? We don't have to.</p>
<p class="info"><em>Tip</em>: We can make use of <a href="http://docs.jquery.com/Manipulation/wrap#html" rel="external">.wrap()</a> to inject the extra container into our mark-up on-the-fly with JavaScript.</p>
<p>The following calls will add a wrapper div with the class .xtra to our box, then proceed to round our inner box (.border) with a radius of 15px, before padding .xtra with 5px of "border" (whitened with CSS on .xtra) and rounding with a 20px radius:</p>
<pre><code>$('div.border').wrap("&lt;div class='xtra'&gt;&lt;/div&gt;");
$('div.border').corner("15px").parent().css('padding', '5px').corner("20px");</code></pre>
<p>This will have the following effect on our test box:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/border.jpg" width="274" height="356" alt="border.jpg" /></p>
<h4>Case 4: Drop shadows</h4>
<p>In researching this article I came across three ways to create drop shadows using jQuery:</p>
<ul>
<li><a href="http://edgarverle.com/shadow/default.cfm" rel="external">Shadow</a> is an extension that uses tables with multiple rows subject to CSS styling including varying opacity to create a drop shadow illusion;</li>
<li>A <a href="http://15daysofjquery.com/wrap-it-up-lazy-mans-html-generation-with-jquery/10/" rel="external">method</a> that uses images and "onion skin" CSS added via <a href="http://docs.jquery.com/Manipulation/wrap#html" rel="external">.wrap()</a> to add a drop shadow;</li>
<li>UI/Shadow.</li>
</ul>
<p><a href="http://docs.jquery.com/UI/Shadow" rel="external">UI/Shadow</a>, available to download <a href="http://dev.jquery.com/view/trunk/fx/fx.shadow.js" rel="external">here</a>, is being folded into the yet-to-be-released jQuery Enchant library. It wraps your element in nested divs and uses opacity to create the shadow effect. It also requires the <a href="http://plugins.jquery.com/project/dimensions/" rel="external">Dimensions</a> plugin. The following call will add a drop shadow to a div with the class . dropshadow:</p>
<pre><code>$('div.dropshadow').shadow({ color: "#444", offset: 5, opacity: 0.2 });</code></pre>
<p>This will have the following effect on our test box:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/dropshadow.jpg" width="269" height="350" alt="dropshadow.jpg" /></p>
<h4>Combining effects and liquid layouts</h4>
<p>As you can see while the effects in cases 1&ndash;4 work well enough on their own, they sadly don't play together very well (<a href="http://www.bioneural.net/wp-content/uploads/2008/02/jquery-tests/jquery-test.html">see</a> Case 5). Whether this is a limitation in one or more of the plugins, or in my scripting know-how I'm not sure.</p>
<p>It is possible to create a rounded box with a border that adjusts to change in text size or window width, but using an image to render the gradient (<a href="http://www.bioneural.net/wp-content/uploads/2008/02/jquery-tests/jquery-test.html">see</a> Case 6). Because the Dimensions plugin employs absolute positioning, effects that use it (gradients, drop shadows) will "detach" from their elements if you try resizing your browser window or changing text size (see the effect on cases 2, 4, and 5).</p>
<h4>The final score</h4>
<p>To be fair I guess we should use the same scoring system to evaluate jQuery against the other methods we explored in <a href="http://www.bioneural.net/2008/02/06/the-best-way-to-do-corners-and-gradients/">Part 1</a>.</p>
<p><strong>Scoresheet:</strong></p>
<p class="for"><em>Photo background</em>: Supported.</p>
<p class="for"><em>Gradient background</em>: Supported (as image or scripted).</p>
<p class="for"><em>Four rounded corners</em>: Yes.</p>
<p class="for"><em>Border</em>: Yes (without extra mark-up).</p>
<p class="for"><em>Drop shadow</em>: Yes (without images).</p>
<p class="for"><em>Minimal mark-up</em>: Extra containers in mark-up can be avoided with <code>.wrap()</code>.</p>
<p class="against"><em>Static mark-up</em>: Mark-up edited to insert box-specific script.</p>
<p class="for"><em>W3C validity</em>: Yes.</p>
<p class="against"><em>Anti-aliasing</em>: No.</p>
<p class="against"><em>Small footprint</em>: 29KB for jQuery plus 19KB for add-on libraries (background images additional). Of course if you're already using jQuery you need only consider the additional size of any add-ons (e.g. shadows for 6KB).</p>
<p class="for"><em>Graceful degradation</em>: Renders as per the master if JavaScript disabled but liquid layouts may cause problems if width is set on containers added with <code>.wrap()</code>.</p>
<p class="for"><em>Liquidity</em>: Yes, with the proviso that you avoid Dimensions-reliant effects.</p>
<p>Score: 9/12 (probably less, because of problems combining effects)</p>
<p>Not enough to de-throne CSS 3 which <a href="http://www.bioneural.net/2008/02/06/the-best-way-to-do-corners-and-gradients/">scored</a> 11/12, or 12/12 if it were a standard. But CSS 3 isn't here yet and won't be widely supported by all major browsers for some time. jQuery is here, however, and JavaScript is widely supported. </p>
<p>Upon reflection there's something to be said for the elegant simplicity and refined geometry of straight lines and sharp corners. This is how the Dwarves would choose to build websites, leaving curves and soft edges to the Elves. So the ultimate question, really, is do you relate more to Gimli or Legolas? Your answer to that, Middle-earthlings, will decide the direction you should take ;-)</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F13%2Fcorners-gradients-and-shadows-with-jquery%2F&amp;seed_title=Corners%2C+gradients+and+shadows+with+jQuery/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>The best way to do corners and gradients</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F06%2Fthe-best-way-to-do-corners-and-gradients%2F&amp;seed_title=The+best+way+to+do+corners+and+gradients</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F06%2Fthe-best-way-to-do-corners-and-gradients%2F&amp;seed_title=The+best+way+to+do+corners+and+gradients#comments</comments>
		<pubDate>Wed, 06 Feb 2008 14:36:17 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[svg]]></category>

		<category><![CDATA[webdev]]></category>

		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2008/02/06/the-best-way-to-do-corners-and-gradients/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>Rounded corners. Yes, they may be a "Web 2.0" fashion fad, but it has been clearly documented that they're a lot easier to <a href="http://www.drivl.com/posts/view/700" rel="external">make</a> than square ones. As part of my <a href="http://www.bioneural.net/2007/12/27/a-xmas-spent-upgrading-bioneuralnet/">overhaul</a> of bioneural.net I've been optimizing much of the code "under the hood", meaning a lot of the changes aren't even visible. Re-evaluating how things are put together, and considering how they could be done more efficiently or otherwise improved is a valuable exercise&mdash;that it scratches a perfectionist itch is an added bonus. In this article I look at a variety of methods for creating boxes with rounded corners and gradients. Yep, it's a showdown!<br />
<span id="more-809"></span></p>
<h4>The traditional approach</h4>
<p>The well-established method of adding corners or gradients to an element is to use multiple background images. Depending to some extent on your content, this is typically impossible to achieve without the use of non-semantic extra mark-up. For example, this box uses to extra and empty divs:</p>
<pre><code>&lt;div class="curvetop"&gt;&lt;/div&gt;
&lt;div class="curvemid"&gt;
	&lt;h2&gt;Willkommen! Welcome!&lt;/h2&gt;
	&lt;p class="german" xml:lang="de" lang="de"&gt;Willkommen auf der Projekt Koru Seite, wo Simone &amp;amp; Bruce die praktischen Aspekte eines Jahres in Neuseeland mit Euch teilen wollen. Eine Einf&amp;uuml;hrung findet Ihr &lt;a href="http://www.bioneural.net/2006/03/17/introducing-project-koru/"&gt;hier&lt;/a&gt; zusammen mit einer &lt;a href="http://www.bioneural.net/2006/03/30/the-teachings-of-te-koru/"&gt;Erkl&amp;auml;rung&lt;/a&gt; warum wir das Koru als Symbol unserer Reise gew&amp;auml;hlt haben.&lt;/p&gt;
	&lt;p class="english"&gt;Welcome to Project Koru, where Simone &amp;amp; Bruce share insight into the practicalities of organizing a year in New Zealand. You can find an introduction to the project &lt;a href="http://www.bioneural.net/2006/03/17/introducing-project-koru/"&gt;here&lt;/a&gt; together with an &lt;a href="http://www.bioneural.net/2006/03/30/the-teachings-of-te-koru/"&gt;explanation&lt;/a&gt; of why we chose the koru as the symbol for our journey.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="curvebottom"&gt;&lt;/div&gt;</code></pre>
<p>Three gradient images (2 having one rounded corner each) could then be loaded into the background of each of the three "layout classes" via CSS:</p>
<pre><code>.curvetop { height: 15px; background: #fff url('gradient-top.png') bottom left no-repeat; display: block; position: relative; margin-top: 10px; }
.curvemid { background: #fff url('gradient-bg.png') repeat-y; padding: 2px 20px !important; display: block; }
.curvebottom { height: 15px; background: #fff url('gradient-bottom.png') top left no-repeat; display: block; position: relative; margin-bottom: 10px; }</code></pre>
<p>The result:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/rounded-welcome.jpg" width="450" height="161" alt="rounded-welcome.jpg"/></p>
<p>You could use this exact same technique for adding embellishments like borders, drop shadows and the like&mdash;but not without some Photoshop skills and a decent collection of bandwidth-hogging images if you needed multiple box styles.</p>
<h4>The challenge</h4>
<p>I devised a box that I thought would test the mettle of any technique. It consisted of just one div containing a header and a paragraph, the text in each of which should appear over a different background with one of these being a gradient (but not necessarily an image). The box should be formed with rounded corners (including on images), a white border, and a drop shadow. It should also have a number of functional characteristics:</p>
<ul>
<li>Minimal mark-up i.e. avoiding nested and/or empty tags;</li>
<li>No changes to mark-up required (but extra CSS allowed, since this could be moved to an external stlesheet);</li>
<li>Valid XHTML and CSS (2.1);</li>
<li><a href="http://en.wikipedia.org/wiki/Anti-aliasing" rel="external">Anti-aliasing</a> on the corners (inner and outer border edges);</li>
<li>Small footprint (let's say under 20KB);</li>
<li>If using JavaScript it should degrade gracefully (i.e. still looks OK if JavaScript is disabled);</li>
<li>Liquid container (adjusting container width to both content size and browser window dimensions).</li>
</ul>
<p class="info">Why the requirement for minimal markup? Forward planning. Eventually CSS3 will arrive, and there'll be no need to scour your database in order to clean out all that redundant mark-up. Just amend your CSS and delete any unemployed images or JavaScript.</p>
<p>My template XHTML and CSS rendered the following:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/master.jpg" width="271" height="354" alt="master.jpg" /></p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/master/master-test.html">live</a> link.</p>
<p>Finding a solution to fulfil most if not all of my form and function requirements was going to be something of a mission. There's a useful roundup of techniques <a href="http://www.smileycat.com/miaow/archives/000044.php" rel="external">here</a>, divided into those based on CSS and those based on JavaScript, with examples in both groups requiring anything from no images at all through to eight images. A particular difficulty was finding techniques not restricted by the dimensions of any required image; many of the earlier established methods were clearly devised before the availability of 23" widescreen displays (<a href="http://www.456bereastreet.com/lab/transparent_custom_corners_borders/customised.html">example</a>.)</p>
<p>I made a shortlist (in no particular order) of techniques that looked promising and set to work. I'm not going to post all the code directly into this article or it will become over-long. The files I used for each technique, together with the master template and original full packages where applicable, are available for download should you wish checkout the code or conduct further experiments. I've tested only in Safari and Firefox.</p>
<p class="download">Download the test files <a href="http://www.bioneural.net/docs/corner-tests.zip">here</a> (.zip archive, 428KB).</p>
<h4>Nifty Corners Cube</h4>
<p>First up is <a href="http://www.html.it/articoli/niftycube/index.html" rel="external">Nifty Corners Cube</a> by Alessandro Fulciniti. This method uses JavaScript and CSS; no images other than those you wish to use as backgrounds are required. Here is the result:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/nifty.jpg" width="285" height="366" alt="nifty.jpg" /></p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/nifty/nifty-test.html">live</a> link.</p>
<p><strong>Scoresheet:</strong></p>
<p class="for"><em>Photo background</em>: Supported.</p>
<p class="for"><em>Gradient background</em>: Supported.</p>
<p class="for"><em>Four rounded corners</em>: Yes.</p>
<p class="for"><em>Border</em>: While you can produce a <a href="http://www.html.it/articoli/niftycube/nifty11.html" rel="external">convincing</a> rounded border, using padding on the container, this would require extra mark-up in our example in order to retain the cornering on our background images.</p>
<p class="against"><em>Drop shadow</em>: Not supported.</p>
<p class="against"><em>Minimal mark-up</em>: An extra container is required to render a border with inside and outside rounding.</p>
<p class="against"><em>Static mark-up</em>: Mark-up edited to add extra container plus insert box-specific script.</p>
<p class="for"><em>W3C validity</em>: Yes.</p>
<p class="against"><em>Anti-aliasing</em>: Anti-aliasing is not working on the background images or border, although it does work on solid colour boxes in the <a href="http://www.html.it/articoli/niftycube/nifty1.html" rel="external">examples</a>.</p>
<p class="for"><em>Small footprint</em>: 10KB for CSS and JavaScript (background images additional).</p>
<p class="for"><em>Graceful degradation</em>: Renders as per the master if JavaScript disabled.</p>
<p class="for"><em>Liquidity</em>: Overriding fixed width for .cornered (and in the third case for .xtra) supports liquid layouts (case four).</p>
<p>Score: 8/12</p>
<h4>curvyCorners</h4>
<p>Cameron Cooke's <a href="http://www.curvycorners.net/" rel="external">curvyCorners</a> is another image-free JavaScript solution:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/curvy.jpg" width="287" height="373" alt="curvy.jpg" /></p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/curvy/curvy-test.html">live</a> link.</p>
<p><strong>Scoresheet:</strong></p>
<p class="for"><em>Photo background</em>: Supported.</p>
<p class="for"><em>Gradient background</em>: Supported.</p>
<p class="against"><em>Four rounded corners</em>: There are rounded corners, but these are rendered adjacent to our background content rather than on top of it. This <a href="http://www.curvycorners.net/examples/demos/demo2.html" rel="external">example</a> illustrates rounding on a background image, but adding a border to the containing div merely fills the cornered area with "extra" offset background (see <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/curvy/offset.jpg">here</a>).</p>
<p class="for"><em>Border</em>: Obtained by applying background and border to container.</p>
<p class="against"><em>Drop shadow</em>: Not a feature of this technique.</p>
<p class="for"><em>Minimal mark-up</em>: Yes.</p>
<p class="against"><em>Static mark-up</em>: Mark-up edited to insert box-specific script.</p>
<p class="for"><em>W3C validity</em>: Yes.</p>
<p class="against"><em>Anti-aliasing</em>: Yes, but only on the outside of the rounded border (not on images).</p>
<p class="against"><em>Small footprint</em>: 24KB for JavaScript (background images additional).</p>
<p class="for"><em>Graceful degradation</em>: Renders as per the master if JavaScript disabled.</p>
<p class="for"><em>Liquidity</em>: Overriding fixed width for .cornered supports liquid layouts (case four).</p>
<p>Score: 7/12</p>
<h4>SRCCB</h4>
<p>The "simple rounded corner CSS boxes" technique was <a href="http://www.modxcms.com/simple-rounded-corner-css-boxes.html" rel="external">devised</a> by Ryan Thrash, also accessible in the form of an online generator as <a href="http://spiffybox.com/" rel="external">Spiffy Box</a>. It uses no JavaScript and a single image combined with moderately complex CSS (which would have to be recalculated for each box size):</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/simple.jpg" width="268" height="374" alt="simple.jpg" /></p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/simple/simple-test.html">live</a> link.</p>
<p><strong>Scoresheet:</strong></p>
<p class="for"><em>Photo background</em>: Supported (integrated into container background).</p>
<p class="for"><em>Gradient background</em>: Supported (integrated into container background).</p>
<p class="for"><em>Four rounded corners</em>: Yes (integrated into container background).</p>
<p class="for"><em>Border</em>: Yes (integrated into container background).</p>
<p class="for"><em>Drop shadow</em>: Yes (integrated into container background).</p>
<p class="against"><em>Minimal mark-up</em>: Requires two additional divs for positioning purposes.</p>
<p class="against"><em>Static mark-up</em>: Mark-up edited to insert two additional divs.</p>
<p class="for"><em>W3C validity</em>: Yes.</p>
<p class="for"><em>Anti-aliasing</em>: Yes (integrated into container background).</p>
<p class="for"><em>Small footprint</em>: 6KB image overhead compared to master with original 2 background images.</p>
<p class="for"><em>Graceful degradation</em>: Not applicable as no JavaScript.</p>
<p class="against"><em>Liquidity</em>: Depends upon fixed-width images.</p>
<p>Score: 9/12</p>
<h4>swfIR</h4>
<p>The SWF Image Replacement (<a href="http://www.swfir.com" rel="external">swfIR</a>) technique is offered by Jon Aldinger, Mark Huot, and Dan Mall. It applies to inline (cf background) images and uses JavaScript and Flash to swap out the original and deck it out with bling. It does more than we require&mdash;image rotation and stretching for example, and at first glance it certainly looked like the wrong tool for the job. I wondered, however, if we could use CSS positioning to overlay our text on top of the replaced images. It turns out you can:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/swfir.jpg" width="255" height="394" alt="swfir.jpg" /></p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/swfir/swfir-test.html">live</a> link.</p>
<p><strong>Scoresheet:</strong></p>
<p class="for"><em>Photo background</em>: Supported (as an inline image!).</p>
<p class="for"><em>Gradient background</em>: Supported (as an inline image!).</p>
<p class="against"><em>Four rounded corners</em>: Actually you get 6! (you could potentially blot out the bottom border on the heading using a third positioned inline image&mdash;a real hack!).</p>
<p class="for"><em>Border</em>: Yes (specified in JavaScript).</p>
<p class="for"><em>Drop shadow</em>: Yes (specified in JavaScript).</p>
<p class="against"><em>Minimal mark-up</em>: Requires insertion of two inline images.</p>
<p class="against"><em>Static mark-up</em>: Mark-up edited to insert inline images plus box-specific script.</p>
<p class="for"><em>W3C validity</em>: Yes. It does validate, but should I say "No" because it depends on Flash?</p>
<p class="for"><em>Anti-aliasing</em>: Yes.</p>
<p class="against"><em>Small footprint</em>: 25KB (24KB JavaScript and SWF; 1KB image overhead compared to master with original 2 background images.)</p>
<p class="for"><em>Graceful degradation</em>: Acceptable (just) with JavaScript disabled.</p>
<p class="against"><em>Liquidity</em>: Positioning depends upon fixed-width images.</p>
<p>Score: 7/12</p>
<h4>ShadedBorder</h4>
<p>Steffen Ruzee brings you <a href="http://www.ruzee.com/blog/shadedborder" rel="external">ShadedBorder</a>, a full-featured solution that uses only JavaScript:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/shaded.jpg" width="273" height="374" alt="shaded.jpg" /></p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/shaded/shaded-test.html">live</a> link.</p>
<p><strong>Scoresheet:</strong></p>
<p class="for"><em>Photo background</em>: Supported.</p>
<p class="for"><em>Gradient background</em>: Supported.</p>
<p class="for"><em>Four rounded corners</em>: Yes.</p>
<p class="against"><em>Border</em>: Yes (specified in JavaScript), but height on .sb-inner causes blue background to show through (why isn't this also an issue with the h4 background image?). Setting height to 0 removes the bar but also takes out the gradient! Admittedly, you could style the background to tone in better.</p>
<p class="for"><em>Drop shadow</em>: Yes (specified in JavaScript).</p>
<p class="against"><em>Minimal mark-up</em>: A headline with it's own style can be <a href="http://www.ruzee.com/files/shadedborder/test.html" rel="external">achieved</a> with extra mark-up, and extra script in the head, and another script that <em>must</em> be inserted before the closing body tag. This makes it fatally flawed for use in a templated system like WordPress, IMHO.</p>
<p class="against"><em>Static mark-up</em>: As above, mark-up edited at 3 points, including a necessary change from div class to ID.</p>
<p class="for"><em>W3C validity</em>: Yes.</p>
<p class="for"><em>Anti-aliasing</em>: Yes.</p>
<p class="for"><em>Small footprint</em>: 9KB JavaScript.</p>
<p class="for"><em>Graceful degradation</em>: Renders as per the master if JavaScript disabled.</p>
<p class="for"><em>Liquidity</em>: Yes (comment out width on #cornered; not shown due to duplicate IDs).</p>
<p>Score: 9/12</p>
<h4>SVG</h4>
<p>Firefox 2 and Safari 3 can both display standalone Scalable Vector Graphics (<a href="http://www.w3.org/TR/SVG/" rel="external">SVG</a>) images, an unloved W3C standard. They can't load SVG from CSS, however, making SVGs unusable as background images at this time. The option to use SVG in CSS hasn't gone beyond a <a href="http://dbaron.org/css/css-vg/" rel="external">proposal</a>, with Wikipedia <a href="http://en.wikipedia.org/wiki/Scalable_Vector_Graphics" rel="external">noting</a> "the use of SVG on the web is in its infancy". It took me quite a few hours to get to grips with the examples in the 1.1 spec and create a <a href="http://validator.w3.org/check?uri=http%3A//www.bioneural.net/wp-content/uploads/2008/02/corner-tests/svg/svg-test.xhtml" rel="external">valid</a> and functional XHTML/SVG file for testing purposes. The basic idea is to create a bordered box with rounded corners, fill it with a gradient, and apply a <a href="http://en.wikipedia.org/wiki/Gaussian_blur" rel="external">Gaussian blur</a> to a slightly offset box of the same dimensions&mdash;all with a few lines of XML. Here is our box using Opera 9.25 (Mac):</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/svg.jpg" width="279" height="372" alt="svg.jpg" /></p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/svg/svg-test.xhtml">live</a> link (SVG-aware browser required).</p>
<p><strong>Scoresheet:</strong></p>
<p class="against"><em>Photo background</em>: Supported in CSS, but you loose the rounded corners.</p>
<p class="for"><em>Gradient background</em>: Supported without CSS via <code>linearGradient</code>.</p>
<p class="for"><em>Four rounded corners</em>: Yes via <code>rx</code> on <code>rect</code>.</p>
<p class="for"><em>Border</em>: Yes via <code>stroke</code> on <code>rect</code>.</p>
<p class="for"><em>Drop shadow</em>: Yes via <code>filter</code> with <code>feGaussianBlur</code>, <code>feOffset</code>, and <code>feMerge</code>.</p>
<p class="against"><em>Minimal mark-up</em>: Requires insertion of inline SVG image(s).</p>
<p class="against"><em>Static mark-up</em>: SVG must (currently) be added inline; also necessitates DOCTYPE change and .xhtml file extension.</p>
<p class="for"><em>W3C validity</em>: Yes.</p>
<p class="for"><em>Anti-aliasing</em>: Yes.</p>
<p class="for"><em>Small footprint</em>: 0KB (background image additional; gradient image not required).</p>
<p class="against"><em>Graceful degradation</em>: No (Internet Explorer 6 and 7 choke).</p>
<p class="against"><em>Liquidity</em>: Positioning depends upon fixed-width SVG images; <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/svg/svg-resize-test.xhtml">resizing</a> text size or browser window is problematic.</p>
<p>Score: 7/12</p>
<p><em>Update 18.03.08</em>: Safari 3.1 <a href="http://docs.info.apple.com/article.html?artnum=307467" rel="external">adds</a> support for SVG images in img elements and CSS images.</p>
<h4>CSS3</h4>
<p><a href="http://www.w3.org/TR/css3-roadmap/" rel="external">CSS3</a>, if it ever arrives, promises not only rounded corners but drop shadows and multiple background images too (oddly the draft spec doesn't mention gradients). Apple's <a href="http://www.apple.com/safari/" rel="external">Safari</a> (available for Mac and PC) already includes support for such effects&mdash;but of course it's not valid CSS. You can preview CSS3 rounded corners <a href="http://www.css3.info/preview/rounded-border/" rel="external">here</a> and <a href="http://24ways.org/2006/rounded-corner-boxes-the-css3-way" rel="external">here</a> in Firefox or Safari 3. Here is our box using Safari-specific not-quite-CSS3:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/css3.jpg" width="293" height="371" alt="css3.jpg" /></p>
<p class="link">Here is the <a href="http://www.bioneural.net/wp-content/uploads/2008/02/corner-tests/css3/css3-test.html">live</a> link (<a href="http://webkit.org/" rel="external">WebKit</a> browser required).</p>
<p><strong>Scoresheet:</strong></p>
<p class="for"><em>Photo background</em>: Supported.</p>
<p class="for"><em>Gradient background</em>: Supported.</p>
<p class="for"><em>Four rounded corners</em>: Yes.</p>
<p class="for"><em>Border</em>: Yes.</p>
<p class="for"><em>Drop shadow</em>: Yes.</p>
<p class="for"><em>Minimal mark-up</em>: Yes.</p>
<p class="for"><em>Static mark-up</em>: Yes.</p>
<p class="against"><em>W3C validity</em>: No, but only because the standard isn't yet established.</p>
<p class="for"><em>Anti-aliasing</em>: Yes, but note anti-aliasing artefact in the bottom corners.</p>
<p class="for"><em>Small footprint</em>: 0KB (background images additional).</p>
<p class="for"><em>Graceful degradation</em>: Yes (non-CSS3 aware browsers see a plain box).</p>
<p class="for"><em>Liquidity</em>: Yes.</p>
<p>Score: 11/12</p>
<h4>Summing up</h4>
<p>Which technique you choose ultimately depends upon what you're after and what you prioritise. There is no one "best" solution that fits all requirements. In terms of form and function CSS3 has to be the clear winner if one must be chosen, with a perfect score blown only by the fact that it isn't a W3C standard (yet). Herein lies CSS3's only significant yet overwhelming drawback: what good is it if the majority users can't see the effects? At the same time I'm not personally sold on any of the alternative methods. The end results may look good; it's <em>how</em> they achieve them that I don't much care for. Although a method validates it typically involves cheating the validator (seemingly JavaScript's <em>raison d'être</em>). Just take a look at the live links with Safari's Web Inspector (<a href="http://www.bioneural.net/wp-content/uploads/2008/02/inspector.jpg">example</a>).</p>
<p>Before I put a lid on this little adventure, as Jobs would <a href="http://en.wikipedia.org/wiki/Stevenote" rel="external">say</a>, there's just <em>one more thing</em>... what about jQuery? The <a href="http://jquery.com/" rel="external">jQuery</a> library (included with WordPress and the K2 theme) can be extended to render corners, shadows, and gradients. If this article was Part 1, then that exposition forms <a href="http://www.bioneural.net/2008/02/13/corners-gradients-and-shadows-with-jquery/">Part 2</a>. <del datetime="2008-02-13T16:15:23+00:00">Coming soon</del>.</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F06%2Fthe-best-way-to-do-corners-and-gradients%2F&amp;seed_title=The+best+way+to+do+corners+and+gradients/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>IE6, italics, and overflow issues</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F01%2Fie6-italics-and-overflow-issues%2F&amp;seed_title=IE6%2C+italics%2C+and+overflow+issues</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F01%2Fie6-italics-and-overflow-issues%2F&amp;seed_title=IE6%2C+italics%2C+and+overflow+issues#comments</comments>
		<pubDate>Fri, 01 Feb 2008 14:12:48 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2008/02/01/ie6-italics-and-overflow-issues/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>Since I began <a href="http://www.bioneural.net/2007/12/27/a-xmas-spent-upgrading-bioneuralnet/">revamping</a> my site (mostly under-the-hood) at Xmas I've tracked down and eliminated a number of long-standing bugs. I'm now satisfied that my site renders acceptably using Firefox, Safari, IE6 and 7, and across both my primary and <a href="http://www.bioneural.net/2008/01/22/bioneuralnet-site-preference-panel-revisited/">alternate</a> styles. Thankfully the majority of bugs I've encountered have been well described and have had solutions documented. But it's matching your issue to the bug description that's the hard part. One particular IE6 bug took me a while to identify because it seemed so random: some pages were inexplicably wider than the fixed-width of 780px by 3px.<br />
<span id="more-805"></span></p>
<h4>The problem</h4>
<p>Because my header image is exactly the width of my page container, the effect of the expanded container was readily visible in IE6:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/ie6-header.jpg" width="85" height="200" alt="ie6-header.jpg"/></p>
<h4>Playing detective</h4>
<p>Starting with an afflicted page I deleted content first from the sidebar, and then from the main content area, adding it back one chunk at a time to see which element was responsible for causing the anomaly. By so doing I narrowed it down to one particular text-only paragraph. The mark-up was perfectly valid and contained no floats, padding, or borders that IE6 loves to choke on.</p>
<p>Firefox's <a href="http://chrispederick.com/work/web-developer/" rel="external">Web Developer Extension</a> has a topographic overlay which is extremely valuable for checking element widths (especially when combined with the new Dimensions "laser" in the indispensable <a href="http://iconfactory.com/software/xscope/" rel="external">xScope</a>, now at v2.0). That looked fine, but the breakthrough came when I tried outlining divs in Internet Explorer 7 with the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=e59c3964-672d-4511-bb3e-2d5e1db91038" rel="external">Developer Toolbar</a>. I noticed that italics rendered outside the div outline:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/ie7.jpg" width="121" height="156" alt="ie7.jpg"/></p>
<p>Sure enough, now I knew what to look for I could see this in both Safari (left) and IE6 (right):</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/02/compare.jpg" width="256" height="295" alt="compare.jpg"/></p>
<p>I temporarily removed the italics from my troublesome paragraph, and the problem went away.</p>
<h4>The solution</h4>
<p>It turned out that changing width to accomodate italics in a block of specified width was a <a href="http://www.positioniseverything.net/explorer/italicbug-ie.html" rel="external">known</a> IE6 bug: just not one I'd encountered before. The fix was simple. Since I was already using <a href="http://msdn2.microsoft.com/en-us/library/ms537512.aspx" rel="external">conditional comments</a> to feed bug fixes to IE6 I just needed to add one line to my IE6-specific stylesheet:</p>
<pre><code>#primary { overflow: visible; }</code></pre>
<p>As noted by PIE, it makes no sense at all since "visible" is the default value of overflow anyway. But you can't expect logical behaviour from IE6 can you?</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F02%2F01%2Fie6-italics-and-overflow-issues%2F&amp;seed_title=IE6%2C+italics%2C+and+overflow+issues/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>bioneural.net site preference panel revisited</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F22%2Fbioneuralnet-site-preference-panel-revisited%2F&amp;seed_title=bioneural.net+site+preference+panel+revisited</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F22%2Fbioneuralnet-site-preference-panel-revisited%2F&amp;seed_title=bioneural.net+site+preference+panel+revisited#comments</comments>
		<pubDate>Tue, 22 Jan 2008 20:06:51 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[webdev]]></category>

		<category><![CDATA[wordpress]]></category>

		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2008/01/22/bioneuralnet-site-preference-panel-revisited/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>The <a href="http://www.bioneural.net/2006/05/11/adding-a-site-preferences-panel/">first</a> version of my site preference panel for <a href="http://wordpress.org/" rel="external">WordPress</a> needed lots of JavaScript for the toggle (<a href="http://www.bioneural.net/2008/01/06/from-protoaculous-to-jquery/">Proto.aculo.us</a>), more JavaScript to switch styles, and still more JavaScript to change text size. Version 2 still uses JavaScript for the toggle effect&mdash;but no additional load&mdash;since jQuery is already utilised by <a href="http://getk2.com/" rel="external">K2</a>. The rest is accomplished using server-side PHP, and the revised 3-column panel layout makes use of more recent CSS know-how. I've tried to modularize the preferences panel as much as possible, but some simple template editing is still required (at 4 points). It is optimised for K2 (tested using RC3 and RC4) and although I haven't tested it with other themes (that's your job!) I don't see why it couldn't be used (*Some tweaking may be required. Batteries not included.)<br />
<span id="more-785"></span></p>
<h4>Get the files</h4>
<p>Let's get it done, then come back to the how and why if you're interested. Download the files to create your own preference panel as siteprefs.zip, available <a href="http://www.bioneural.net/extra/">here</a>. Expand the archive and upload the folder "siteprefs" into your K2 main directory:</p>
<p>/wp-content/themes/k2/siteprefs/</p>
<p>At this point you may also want to download and activate the <a href="http://wordpress.org/extend/plugins/theme-switcher/" rel="external">Theme Switcher</a> plugin if you plan on allowing your audience to change the WordPress theme they see on a per-user basis (storing their preference in a cookie). Support for the plugin is built into the preference panel (see features, below).</p>
<p>It's yours to play with and customise; all I ask is that you retain the little "i" icon with it's link back to these instructions. Feedback and suggestions for improvement are welcome. If you do modify it in a novel way (or use it in a theme other than K2), please leave a comment so I and others can check it out.</p>
<p>Right then, let's hack some templates!</p>
<h4>Step 1: Look for cookies</h4>
<p>Add the following code into PHP block at the top of K2's header.php (e.g. before the closing "?&gt;"):</p>
<pre><code>// Check cookie for stored site prefs
$layout = (isset($_COOKIE['layout']) &amp;&amp; ($_COOKIE['layout'] == "alternate")) ? "alternate" : "style";</code></pre>
<p>Here, "style" is the name of your main stylesheet (style.css in K2) and "alternate" is the name of a stylesheet we'll create at Step 5. If you're not using K2 pop this between PHP start and end tags at the top of your header template and set "style" to the name of your primary CSS file.</p>
<h4>Step 2: Know your style</h4>
<p>We need to replace the relative link to your stylesheet with one into which we can insert the value of the variable <code>$layout</code>. While we're here, we might as well link to the styling for the preference panel. In the head element of header.php replace this line (or your theme's equivalent):</p>
<pre><code>&lt;link rel="stylesheet" type="text/css" media="screen" href="&lt;?php bloginfo('stylesheet_url'); ?&gt;" /&gt;</code></pre>
<p>with:</p>
<pre><code>&lt;link rel="stylesheet" type="text/css" media="screen" href="&lt;?php bloginfo('template_url'); ?&gt;/&lt;?php echo $layout; ?&gt;.css" /&gt;
&lt;link rel="stylesheet" type="text/css" media="screen" href="&lt;?php bloginfo('template_url'); ?&gt;/siteprefs/siteprefs.css" /&gt;</code></pre>
<p class="info">Your K2 custom stylesheet will still be loaded too, if you're using one.</p>
<h4>Step 3: Flick the switch</h4>
<p>Create a toggle to switch visibility of the preference panel on or off (it will be hidden on page load). The actual "switch" might be a text or an image link, inserted into an appropriate place (e.g your header or sidebar). If you prefer to add the toggle in the form of a tab in your K2 menu, look for <code>ul class="menu"</code> in header.php and replace this code:</p>
<pre><code>	&lt;?php wp_register('&lt;li class="admintab"&gt;','&lt;/li&gt;'); ?&gt;
&lt;/ul&gt;</code></pre>
<p>with the following code:</p>
<pre><code>	&lt;?php wp_register('&lt;li class="admintab"&gt;','&lt;/li&gt;'); ?&gt;
	&lt;li&gt;&lt;a id="siteprefs-toggle" href="#" title="Click to show/hide site preferences (requires JavaScript)"&gt;Prefs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;script type="text/javascript"&gt;
	jQuery(document).ready(function() {

	// hide #siteprefs as soon as the DOM is ready
	jQuery('#siteprefs').hide();

	// toggle #siteprefs on clicking the #prefs-toogle link
	jQuery('a#siteprefs-toggle').click(function() {
	jQuery('#siteprefs').slideToggle(400);
	return false;
	});

});
&lt;/script&gt;</code></pre>
<p>If you'd rather use the supplied image (sitepref2.gif), place the following code after <code>p class="description"</code> (which is within <code>div id="header"</code>) and before <code>ul class="menu"</code> in K2's header.php. </p>
<pre><code>&lt;a id="siteprefs-toggle" href="#" title="Click to show/hide site preferences (requires JavaScript)"&gt;&lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;/siteprefs/img/sitepref2.gif" width="52" height="28" alt="siteprefs" /&gt;&lt;/a&gt;
&lt;script type="text/javascript"&gt;
	jQuery(document).ready(function() {

	// hide #siteprefs as soon as the DOM is ready
	jQuery('#siteprefs').hide();

	// toggle #siteprefs on clicking the #prefs-toogle link
	jQuery('a#siteprefs-toggle').click(function() {
	jQuery('#siteprefs').slideToggle(400);
	return false;
	});

});
&lt;/script&gt;</code></pre>
<p>The CSS to position the #siteprefs-toggle image within K2's header image area is included in the download (it will be ignored if you create a menu tab instead). If this position doesn't suit your theme of course you can overwrite this in siteprefs.css. </p>
<p class="info">The toggle's "slide" effect depends on jQuery, which comes with K2 by default. If you're not using K2, you'll need to include the jQuery library in your head, find an alternative JavaScript (<a href="http://www.bioneural.net/2006/05/11/adding-a-site-preferences-panel/">here</a> is how v1 did it using Proto.aculo.us), or you may wish to dispense with the toggle altogether and ventilate your preferences permanently.</p>
<h4>Step 4: Feel included</h4>
<p>The file siteprefs.php includes the XHTML and PHP to build your preference panel. As well as providing the Theme Switcher control, it works with layout.php to toggle your main and alternate stylesheets (and store your choice in a cookie), and advises your audience on link behaviour. You can change the content of these three columns as you see fit just by editing siteprefs.php.</p>
<p>To get siteprefs.php into your theme we have to include it e.g. immediately below the closing tag of the div #header in header.php, so it appears to slide out from the K2 menu:</p>
<pre><code>&lt;?php include (TEMPLATEPATH . '/siteprefs/siteprefs.php'); ?&gt;</code></pre>
<p>If you prefer you could put it at the top of your page, in the sidebar, or in the footer. Or anywhere. For sidebar placement, for example, you would likely edit siteprefs.php and siteprefs.css to respectively create and style a single vertical column.</p>
<p>At this point, if you refresh your site you should see the bioneural.net preference panel installed. If all went well and you're using a default K2 installation, you should be something like this:</p>
<p><span class="zoom">Click thumbnail to enlarge image</span><br /><a href="http://www.bioneural.net/images/enlarge/siteprefs-large.jpg" rel="ibox" title="Site preferences installed into default K2 theme (using image toggle)"><img src="http://www.bioneural.net/wp-content/uploads/2008/01/siteprefs-thumb.jpg" width="200" height="81" alt="siteprefs-thumb.jpg" /></a><br /><span class="caption">Site preferences installed into default K2 theme (using image toggle)</span></p>
<h4>Step 5: Go alternative</h4>
<p>Finally we create an alternate stylesheet, named alternate.css (the name is specified in Step 1 and in layout.php).</p>
<p>What you put in here is up to you. You will likely want to import existing styling from your main stylesheet, and then write a handful of rules which, owing to the CSS "cascade", will overwrite some of those you just imported. </p>
<p>Here's a barebones example that increases font size and turns the default K2 fixed-width theme into a fluid/ liquid layout:</p>
<pre><code>@import 'style.css';

body { font-size: 90%; } /* approx 30% larger than K2 default */
#page { width: 100% !important; border: 0; padding: 0; }
#primary { width: 100%; margin-left: -30px; padding-left: 30px; background-color: #fff;}
.content { background-color: #fff; } /* Match bg colour to #primary */
#sidebar-main.secondary { padding-left: 30px; border-right: 10px solid #f2f2f2; padding-bottom: 20px; } /* Border colour matches bg colour of .secondary */
.secondary { width: 100% !important; margin-left: -30px; background: #f2f2f2; }
#footer { background-color: #ccc; }</code></pre>
<p>Upload alternate.css into the same directory as your main stylesheet (e.g. styles.css i.e. /wp-content/themes/k2/). This is <strong>important</strong> as the switch relies on your main and alternate stylesheets being in the same directory.</p>
<p class="info">If you're having trouble overwriting rules for your alternate stylesheet, try !important e.g. <code>width: 100% !important;</code> but bear in mind IE6 will ignore it.</p>
<h4>Build notes, features and credits</h4>
<p>You don't <em>have</em> to read on&mdash;unless you're interested in how, why, and who helped make it work the way it does ;-)</p>
<h4>The toggle effect</h4>
<p>The toggle uses the <a href="http://jquery.com/" rel="external">jQuery</a> JavaScript library and the code for this was covered in a <a href="http://www.bioneural.net/2008/01/06/from-protoaculous-to-jquery/">previous</a> article.</p>
<p>What if the user doesn't have JavaScript, or has it but disabled it? Version 1 hid the preference panel on page load using CSS, and showing it required JavaScript to change the styling to "display". Version 2 uses JavaScript to initially hide the panel, so if there is no JavaScript the panel will be revealed at the outset. Furthermore, because none of the controls in the panel utilize any JavaScript, no functionality is impaired. The only (minor) outcome is that the panel can't be hidden, but at least the "accessibility" preferences are, err, accessible.</p>
<h4>A flexible 3-column framework</h4>
<p>The XHTML mark-up and CSS for this is adapted from an <a href="http://www.alistapart.com/d/multicolumnlayouts/3ColLiquid.html" rel="external">example</a> multi-column layout given in an ALA <a href="http://www.alistapart.com/articles/multicolumnlayouts" rel="external">article</a> by <a href="http://alttag.org/" rel="external">Alan Pearce</a>. Alan cleverly builds on previous work that makes use of borders to simulate equal-height columns. Initially my mark-up used borders too, but after 2 days of trying to get it to work in IE6 and 7 with in-column padding I realised I didn't need them. </p>
<p>The fixed-width two-column K2 theme I use defaults to a width of 780px. To create our basic layout we create 3 divs (one for each column), and wrap these in a container div. The container sets up the 3 columns using floats and negative margins and then uses padding to effectively pull the outer columns back inside the container! We then create a header div and a footer div, and style the width of the outer columns (including padding) to 260px i.e. one third of our page width:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/01/3-columns.jpg" width="451" height="203" alt="3-columns" /></p>
<p>We can then apply a horizontally-repeating background image to the header and footer divs, match the background colours, and clear floats for the footer to position correctly. Here's what our panel now looks like topographically:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/01/topographical.jpg" width="450" height="108" alt="topographical" /></p>
<p>But the preference panel resizes, too. If your alternate stylesheet is "fluid" i.e. page content fits to the width of the browser window, the three columns will automatically space themselves out equally to fill the window:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/01/fluid.jpg" width="450" height="64" alt="fluid" /></p>
<p class="info">Note that the left and right column width doesn't actually change, but the width of the middle column is no longer an implied 260px since we have set #siteprefs-center to occupy 100% width.</p>
<p>At this point everything is looking good&mdash;in Firefox, Safari, and IE7. You guessed it: Internet Exploder 6 is singing protest songs. We need to patch our CSS to make it work with IE6:</p>
<p class="bug">The IE escaping floats <a href="http://www.positioniseverything.net/explorer/escape-floats.html" rel="external">bug</a> causes the contents of #siteprefs-header not to display. We just add <code>width: 100%;</code> to fix this.</p>
<p class="bug">The IE doubled float-margin <a href="http://www.positioniseverything.net/explorer/doubled-margin.html" rel="external">bug</a> causes #siteprefs-right to float outside of #siteprefs-wrapper! To fix this we add <code>display: inline;</code> to #siteprefs-right.</p>
<h4>Switching whole themes</h4>
<p>The <a href="http://wordpress.org/extend/plugins/theme-switcher/" rel="external">Theme Switcher</a> plugin for WordPress is by <a href="http://boren.nu/" rel="external">Ryan Boren</a>. It sets a cookie so that the user's browser remembers their choice of theme for subsequent visits.</p>
<p>The bioneural.net preference panel uses conditional PHP to show the theme switcher dropdown menu or, if the TS plugin is not present or is present but not activated, they will see a "not enabled" message:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/01/styling-states.jpg" width="374" height="122" alt="styling-states.jpg" /></p>
<p>There are a few other things you might consider if you allow theme switching on your site; see Ben's <a href="http://www.instigatorblog.com/10-things-you-must-do-when-changing-wordpress-themes/2007/01/15/" rel="external">list</a>. To press the point, the preference panel includes a warning when the switcher is displayed that using it "may reduce functionality". At the very least you need to allow users to easily switch back to the previous theme&mdash;otherwise they'll have to wait a year until the cookie expires (not really; they could just delete the cookie!). In the sidebar of each theme you have installed, just paste the following:</p>
<pre><code>&lt;?php if (function_exists('wp_theme_switcher')) { ?&gt;
	&lt;?php wp_theme_switcher('dropdown'); ?&gt;
&lt;?php } ?&gt;</code></pre>
<p>If you don't like the list styling, this CSS (as used in siteprefs.css) will remove it:</p>
<pre><code>#themeswitcher { list-style: none; padding-left: 0; }</code></pre>
<h4>Switching stylesheets</h4>
<p>Previously I had used JavaScript to effect both a change in layout (fixed or fluid-width) and in text size (smaller, default, larger). Both of these are really accessibility issues&mdash;adapting to the size of your screen or the acuity of your vision. Add to this the observation that enlarging text size very soon causes problems within the confines of a fixed-width layout and it becomes clear why I decided to merge these features in version 2 i.e. biiger text, bigger container.</p>
<p>Stylesheet switching with memory is ideal, for example, if you want your iPhone/ tablet&mdash;or screen resolution-challenged work PC&mdash;to always use an alternative "accessible" layout. Cookies could likewise ensure that a different default style makes full use of your stunning 23" Apple Display.</p>
<p>Having decided against reusing the <a href="http://www.alistapart.com/stories/alternate/" rel="external">original</a> ALA styleswitcher JavaScript, and considered using jQuery (as <a href="http://kelvinluck.com/article/switch-stylesheets-with-jquery" rel="external">here</a>&mdash;also JavaScript, but better), I looked at a few PHP options and settled on Roger Johansson's <a href="http://www.456bereastreet.com/archive/200608/build_your_own_php_style_sheet_switcher/" rel="external">method</a>.</p>
<h4>Identifying off-site links</h4>
<p>By default (Option 1) any link you tag with rel="external" will display the "off-site" icon (dimmed for visited links) using the included CSS. I prefer this option for identifying off-site links because it gives your audience the choice as to how links behave (the alternative is forcing them to open new windows using JavaScript or the depreciated target="_bank"). If you haven't religiously tagged your off-site links with rel="external" (or can't be bothered), you have two alternative options:</p>
<ol>
<li>Open siteprefs.css and uncomment Option 2 (making sure the CSS for Options 1 and 3 is commented); this will apply the icon to all links other than to your own domain (<a href="http://lachy.id.au/log/2005/04/handy-css" rel="external">credit</a>). See the instructions in the file.</li>
<li>A WordPress <a href="http://sw-guide.de/wordpress/plugins/link-indication/" rel="external">plugin</a> is available that will do it for you (Option 3). Once the Link Indication plugin is activated just uncomment the CSS for Option 3 in siteprefs.css (ensuring the CSS for Options 1 and 2 is commented-out).</li>
</ol>
<p class="info">Option 1 works in Firefox, IE7, and Safari (but not IE6). Option 2 works in Firefox and Safari (but not IE7 or IE6). Option 3 works in Firefox, IE7, IE6, and Safari (but does not differentiate between visited/ unvisited links).</p>
<h4>Change log</h4>
<table class="tabulate">
<tr>
<th>Version</th>
<th>Notes</th>
</tr>
<tr>
<td>1.0</td>
<td class="odd"><em>11.05.06</em>. Initial 1.x release.</td>
</tr>
<tr>
<td>2.0</td>
<td class="odd"><em>22.01.08</em>. Initial 2.x release.</td>
</tr>
<tr>
<td>2.1</td>
<td class="odd"><em>28.01.08</em>. Corrected CSS for off-site links. Added alternative methods of identifying off-site links using <a href="http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#pseudo-classes" rel="external">pseudo-class</a> (Option 2) or class (Option 3).</td>
</tr>
</table>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F22%2Fbioneuralnet-site-preference-panel-revisited%2F&amp;seed_title=bioneural.net+site+preference+panel+revisited/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>From Proto.aculo.us to jQuery</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F06%2Ffrom-protoaculous-to-jquery%2F&amp;seed_title=From+Proto.aculo.us+to+jQuery</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F06%2Ffrom-protoaculous-to-jquery%2F&amp;seed_title=From+Proto.aculo.us+to+jQuery#comments</comments>
		<pubDate>Sun, 06 Jan 2008 18:31:03 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[opensource]]></category>

		<category><![CDATA[webdev]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2008/01/06/from-protoaculous-to-jquery/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>As I recently <a href="http://www.bioneural.net/2007/12/27/a-xmas-spent-upgrading-bioneuralnet/">noted</a>, both WordPress and K2 have migrated from using Prototype plus script.aculo.us to using the <a href="http://jquery.com/" rel="external">jQuery</a> JavaScript library. <a href="http://prototypejs.org/" rel="external">Prototype</a> is a JavaScript framework, including a library of functions used to build <a href="http://en.wikipedia.org/wiki/Ajax_%28programming%29" rel="external">Ajax</a> applications. It's best buddies with <a href="http://script.aculo.us/" rel="external">script.aculo.us</a>, an add-on JavaScript effects library that extends the capabilities of the former. So where does jQuery fit in?<br />
<span id="more-760"></span></p>
<h4>The winds of change</h4>
<p><a href="http://wordpress.org" rel="external">WordPress</a> hasn't altogether dropped either Prototype or script.aculo.us. As of version 2.3.2 they're still bundled in wp-includes/js/, but the <a href="http://codex.wordpress.org/Version_2.2" rel="external">Codex</a> notes that since version 2.2:</p>
<blockquote><p>Switched to jQuery for core JS, which is lighter and faster.</p></blockquote>
<p>I'm no programmer, but I do understand that loading a smaller function library is kinder on your bandwidth and browser, and that writing fewer lines of <a href="http://geekgrl.net/2007/01/04/jquery-vs-prototype-wordpress-gone-astray/" rel="external">script</a> to call those functions is kinder on web developers.</p>
<p><a href="http://getk2.com" rel="external">K2</a>, on the other hand, <a href="http://stevelam.org/2007/08/k2-and-jquery/" rel="external">stopped</a> bundling Prototype and script.aculo.us as of revision 382. This popular WordPress theme now does all its Ajax magic&mdash;Live Search, Rolling Archives, and Live Comments&mdash;via jQuery.</p>
<h4>Loosing weight</h4>
<p>As of this writing Prototype (1.6.0.1) weighs in at 121 KB. The six core files that make up script.aculo.us 1.8.1 (sound.js and unittest.js are optional) also happen to total 121 KB, making a combined size of 242 KB. If I could therefore use jQuery 1.2.1 (at 45 KB) to achieve the same JavaScript-mediated effects, I'd be using around one fifth of the code libraries I was previously loading. But it's worse than that, because if I retained Proto.aculo.us for custom effects <em>and</em> loaded jQuery for K2, I'd be wasting bandwidth and CPU cycles like there was no tomorrow.</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/01/js-libraries.jpg" width="450" height="329" alt="Script library comparison" /></p>
<h4>Prototype plus script.aculo.us</h4>
<p>Here's how I was loading Proto.aculo.us in the head in my old WordPRess K2 r163 theme ("..." is a contracted path):</p>
<pre><code>&lt;script type="text/javascript" src=".../js/prototype.js.php"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src=".../js/effects.js.php"&gt;&lt;/script&gt;</code></pre>
<p>I built a toggle for my sidebar to display a list of category feeds, initially styled not to display on my home page, with the following:</p>
<pre><code>&lt;?php if ((is_home()) &amp;&amp; !(is_paged()) ) { ?&gt;
&lt;div class="sb-catfeeds"&gt;&lt;h2&gt;Category feeds&lt;/h2&gt;
&lt;span class="metalink"&gt;&lt;a href="#catfeed" onclick="Effect.Combo('catfeed', {duration: .5}); return false" title="Click to show/hide category feeds (requires JavaScript)" class="feedlink"&gt;.../styles/bioneural/feedicongrey.png" alt="Feed" /&gt;&lt;/a&gt;&lt;/span&gt;
&lt;noscript&gt;&lt;p class="alert"&gt;Please enable JavaScript for full functionality (toggle feed list visibility)&lt;/p&gt;&lt;/noscript&gt;
&lt;ul id="catfeed" style="display: none;"&gt;
&lt;?php list_cats(0, '', 'name', 'asc', '', 1, 0, 0, 1, 1, 1, 0,'','','Feed','.../images/feedicon16px.png','') ?&gt;
&lt;!-- http://wiki.wordpress.org/list_cats --&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;?php } ?&gt;</code></pre>
<p>A similar arrangement was used to hide and reveal my site <a href="http://www.bioneural.net/2006/05/11/adding-a-site-preferences-panel/">preferences</a> panel. Could I achieve the same using the lightweight jQuery?</p>
<h4>Converting to jQuery</h4>
<p>In my upgraded K2 RC3 theme I'm not loading any additional scripts in the head, because jQuery is already included. If you're not already using jQuery and just want to try it out, you can add it to your head temporarily and without uploading it to your own server like this:</p>
<pre><code>&lt;script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.1.js"&gt;&lt;/script&gt;</code></pre>
<p>Here's what I now have in sidebar.php using jQuery syntax (adapted from <a href="http://www.learningjquery.com/2006/09/slicker-show-and-hide" rel="external">this</a> example):</p>
<pre><code>	&lt;?php if (is_home()) { ?&gt;
	&lt;div class="sb-catfeeds"&gt;&lt;h4&gt;Category feeds&lt;/h4&gt;
	&lt;script type="text/javascript"&gt;
		jQuery(document).ready(function() {

		// hide #catfeed as soon as the DOM is ready
		jQuery('#catfeed').hide();

		// toggle #catfeed on clicking the #catfeed-toogle link
		jQuery('a#catfeed-toggle').click(function() {
		jQuery('#catfeed').slideToggle(400);
		return false;
		});

	});
	&lt;/script&gt;
	&lt;noscript&gt;&lt;p class="alert"&gt;Please enable JavaScript for full functionality (toggle feed list visibility)&lt;/p&gt;&lt;/noscript&gt;
	&lt;span class="metalink"&gt;&lt;a href="#" id="catfeed-toggle" title="Click to show/hide category feeds (requires JavaScript)" class="feedlink"&gt;&lt;img src=".../styles/bioneural/feedicongrey.png" alt="Feed" /&gt;&lt;/a&gt;&lt;/span&gt;
	&lt;ul id="catfeed"&gt;
		&lt;?php wp_list_categories('feed_image=.../images/feedicon16px.png&amp;title_li='); ?&gt;
		&lt;!-- http://codex.wordpress.org/Template_Tags/wp_list_categories --&gt;
	&lt;/ul&gt;
	&lt;/div&gt;
	&lt;?php } ?&gt;</code></pre>
<p>It's as close to poetry as code gets, but initially I was using "$" in place of "jQuery" and the code had no effect at all. Thanks to <a href="http://www.learningjquery.com/2006/09/slicker-show-and-hide#comment-26102">Karl</a> we determined that K2 was already using $, thus leading to the "Error: $ is not a function" I was getting:</p>
<blockquote><p>That error usually occurs when a script tries to use the $ function before the core jQuery file has been loaded or when $ is being used for something else. Try replac[ing] each mention of $ with jQuery and see if that fixes the problem.</p></blockquote>
<h4>Issues</h4>
<p>The only issue I've noticed is that you get a "flash" view of the hidden div when changing pages (on bioneural.net this affects the site preferences panel). While I generally discourage flashing, I don't believe in this case it's an arrestable offence.</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F06%2Ffrom-protoaculous-to-jquery%2F&amp;seed_title=From+Proto.aculo.us+to+jQuery/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Overcoming CSS Validator changes</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2007%2F05%2F05%2Fovercoming-css-validator-changes%2F&amp;seed_title=Overcoming+CSS+Validator+changes</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2007%2F05%2F05%2Fovercoming-css-validator-changes%2F&amp;seed_title=Overcoming+CSS+Validator+changes#comments</comments>
		<pubDate>Sat, 05 May 2007 08:46:41 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[tips]]></category>

		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2007/05/05/overcoming-css-validator-changes/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>A quick follow-up to this <a href="http://www.bioneural.net/2006/04/01/create-a-valid-css-alert-message/">post</a> in which I fell victim to the moving CSS validation goal-post. Do you include a link to the W3C Validator on your site to check your mark-up and CSS for standards compliance? If so you probably tested your code against the CSS profile that was in vogue at the time. But what happens when the W3C release a new profile? They upgrade the Validator&mdash;and your CSS may go from green tick to red cross! Here's a quick tip that avoids having to re-write any CSS, but at the same time keeps you from seeing red.<br />
<span id="more-666"></span><br />
Originally when I created footer.php for my site I included the following CSS validation link:</p>
<pre><code>&lt;a href="http://jigsaw.w3.org/css-validator/validator?uri=http://www.bioneural.net" rel="external" title="Cascading Style Sheets"&gt;CSS&lt;/a&gt;</code></pre>
<p>My pages were valid CSS 2.0. Life was good. But something changed; the W3C began developing CSS 2.1. And I began to see red:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2007/05/css-red.jpg" height="67" width="450" alt="Css-Red" /></p>
<p>The W3C had started to use the draft CSS 2.1 profile as the default for its Validator. The property text-shadow isn't in the 2.1 draft, but it was there in 2.0. I happen to like this effect and wanted to retain it, so the trick is to specify that your website is complying with a specific CSS profile. This is easily accomplished by appending that profile to the URL of the link to the website you are checking, like this:</p>
<pre><code>&lt;a href="http://jigsaw.w3.org/css-validator/validator?uri=http://www.bioneural.net&amp;amp;profile=css2" rel="external" title="Cascading Style Sheets"&gt;CSS&lt;/a&gt;</code></pre>
<p>Now, that's better:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2007/05/css-green.jpg" height="90" width="316" alt="Css-Green" /></p>
<p>It's a small thing, but too many little annoyances can be overwhelming!</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2007%2F05%2F05%2Fovercoming-css-validator-changes%2F&amp;seed_title=Overcoming+CSS+Validator+changes/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Details on CSS changes for IE7</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F10%2F24%2Fdetails-on-css-changes-for-ie7%2F&amp;seed_title=Details+on+CSS+changes+for+IE7</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F10%2F24%2Fdetails-on-css-changes-for-ie7%2F&amp;seed_title=Details+on+CSS+changes+for+IE7#comments</comments>
		<pubDate>Mon, 23 Oct 2006 19:33:18 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Quicklinks]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[Internet]]></category>

		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2006/10/24/details-on-css-changes-for-ie7/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>IE7 is being pushed via Windows Update. The IE7 development team <a href="http://blogs.msdn.com/ie/archive/2006/08/22/712830.aspx" rel="external">document</a> bugs fixed (noted on <a href="http://positioniseverything.net/" rel="external">positioniseverything.net</a> &amp; elsewhere), &amp; extended compliance/ new features from the CSS specs. The IE <a href="http://www.microsoft.com/downloads/details.aspx?familyid=e59c3964-672d-4511-bb3e-2d5e1db91038&amp;displaylang=en" rel="external">Web Developer Toolbar</a> may assist debugging your site for IE7.</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F10%2F24%2Fdetails-on-css-changes-for-ie7%2F&amp;seed_title=Details+on+CSS+changes+for+IE7/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Valid fix for PNG transparency on a single image</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F08%2F09%2Fvalid-fix-for-png-transparency-on-a-single-image%2F&amp;seed_title=Valid+fix+for+PNG+transparency+on+a+single+image</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F08%2F09%2Fvalid-fix-for-png-transparency-on-a-single-image%2F&amp;seed_title=Valid+fix+for+PNG+transparency+on+a+single+image#comments</comments>
		<pubDate>Wed, 09 Aug 2006 21:59:28 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2006/08/09/valid-fix-for-png-transparency-on-a-single-image/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>As you likely know, IE6 (and below) cannot handle <a href="http://en.wikipedia.org/wiki/PNG" rel="external">PNG</a> images that use alpha transparency. PNG produces graphically superior results compared to a transparent GIF image, which will often have a white fuzzy border. There are various "fixes" for this particular IE problem on the Web, but sometimes their application can have undesirable results, or the fix involves invalid XHTML or CSS. In my case I was prepared to accept grey backgrounds on the mini-icons used on bioneural.net, but there was one particular image where this really bugged me. Here's how I fixed it.<br />
<span id="more-544"></span></p>
<h4>A general fix</h4>
<p>At first I tried a JavaScript-based <a href="http://homepage.ntlworld.com/bobosola/" rel="external">solution</a> which was easy to install and automatically applied to all PNG images. Simply load the script in your header, enclosed in IE-specific conditional comments:</p>
<pre><code>&lt;!--[if lt IE 7.]&gt;
&lt;script defer type="text/javascript" src="pngfix.js"&gt;&lt;/script&gt;
&lt;![endif]--&gt;</code></pre>
<p>You can view and download pngfix.js <a href="http://homepage.ntlworld.com/bobosola/pngfix.js" rel="external">here</a>. Notice all those floats? I suspect they were responsible for my giving up on this method. For example, it messed up the feed icons in my sidebar (right, below), and for some reason that particular icon failed to complete loading in the IE progress bar (even though it was obviously being displayed). Weird. I don't like weird:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/08/js-png-fix.jpg" height="266" width="430" alt="Js-Png-Fix" /></p>
<p>I did initially convert the affected images to .jpg (since this issue only affects floated images with a .png extension), but then decided "Why should I bend over backwards just for IE?". I reverted to the PNGs and continued to look for another solution. There's always another solution...</p>
<h4>A specific fix</h4>
<p>I subsequently discovered a <a href="http://www.tjkdesign.com/articles/png_overlay_with_no_extra_markup.asp" rel="external">solution</a> that makes use of proprietary CSS and conditional comments for IE. I have few qualms about using proprietary tricks to fix proprietary mistakes!</p>
<p>Here's the relevant code that sits in my head element:</p>
<pre><code>&lt;!--[if lte IE 6]&gt;
&lt;style type="text/css"&gt;
#pngfixband {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',src='&lt;?php bloginfo('template_directory'); ?&gt;/styles/bioneural/whiteband-9rules-mt.png'); padding-top: 115px; }
&lt;/style&gt;
&lt;![endif]--&gt;</code></pre>
<p>In my header div I've given the image I want to target an id of "pngfixband":</p>
<pre><code>&lt;p id="whiteband"&gt;&lt;a href="http://www.mediatemple.net/.%3E/9r-bioneural.net"&gt;&lt;img id="pngfixband" src="&lt;?php bloginfo('template_directory'); ?&gt;/styles/bioneural/whiteband-9rules-mt.png" alt="White band" width="115" height="115" title="bioneural.net recommends hosting with (mt) Media Temple" /&gt;&lt;/a&gt;&lt;/p&gt;</code></pre>
<p class="info">Notice how the padding (115px) in the styling corresponds to the height of the image specified in the markup? That's important.</p>
<p>In contrast to default behaviour (left, below), IE now does a respectable job of displaying this particular image as per my intentions (right, below)&mdash;but no other PNGs are adversely affected in the process:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/08/png-result.jpg" height="200" width="315" alt="Png-Result" /></p>
<p>No issues either for the XHTML or CSS Validator.</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F08%2F09%2Fvalid-fix-for-png-transparency-on-a-single-image%2F&amp;seed_title=Valid+fix+for+PNG+transparency+on+a+single+image/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.062 seconds -->
