<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Blake Haswell</title>
	<atom:link href="http://blakehaswell.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blakehaswell.wordpress.com</link>
	<description></description>
	<lastBuildDate>Wed, 18 Jan 2012 13:02:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blakehaswell.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Blake Haswell</title>
		<link>http://blakehaswell.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blakehaswell.wordpress.com/osd.xml" title="Blake Haswell" />
	<atom:link rel='hub' href='http://blakehaswell.wordpress.com/?pushpress=hub'/>
		<item>
		<title>LESS Sass. More OOCSS.</title>
		<link>http://blakehaswell.wordpress.com/2011/12/28/less-sass-more-oocss/</link>
		<comments>http://blakehaswell.wordpress.com/2011/12/28/less-sass-more-oocss/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 04:52:31 +0000</pubDate>
		<dc:creator>Blake</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[LESS]]></category>
		<category><![CDATA[OOCSS]]></category>
		<category><![CDATA[Sass]]></category>

		<guid isPermaLink="false">http://blakehaswell.wordpress.com/?p=36</guid>
		<description><![CDATA[CSS preprocessors like LESS and Sass are very popular at the moment, being touted as valuable time-savers for front-end developers. They provide features like variables, mixins, colour manipulation, and the ability to nest CSS rules. These features sound like great &#8230; <a href="http://blakehaswell.wordpress.com/2011/12/28/less-sass-more-oocss/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blakehaswell.wordpress.com&amp;blog=4711557&amp;post=36&amp;subd=blakehaswell&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>CSS preprocessors like <a href="http://lesscss.org/">LESS</a> and <a href="http://sass-lang.com/">Sass</a> are very popular at the moment, being touted as valuable time-savers for front-end developers. They provide features like variables, mixins, colour manipulation, and the ability to nest CSS rules. These features sound like great additions to CSS that could boost productivity, make CSS easier to maintain, and reduce repetition.</p>
<p>Indeed these features sounded so great that I used Sass in a recent project. Having reflected on that project though I have found that Sass&#8217;s features are unnecessary and won&#8217;t actually help you to write better code. If you want to write better code then the key is to write plain old CSS and use the principles described as <a href="https://github.com/stubbornella/oocss/wiki">Object Oriented CSS (OOCSS)</a>.</p>
<h2>What is OOCSS?</h2>
<p>OOCSS is an approach to writing CSS that results in smaller more focused classes which allow much more efficient code re-use. The two main principles of OOCSS are that you should separate structure and skin, and that you should separate container and content. If you&#8217;re not sure what OOCSS is about please read these great resources and then come back:</p>
<ul>
<li>
        <a href="https://github.com/stubbornella/oocss/wiki">Our Best Practices Are Killing Us</a>
    </li>
<li>
        <a href="http://coding.smashingmagazine.com/2011/12/12/an-introduction-to-object-oriented-css-oocss/">An Introduction To Object Oriented CSS</a>
    </li>
<li>
        <a href="https://github.com/stubbornella/oocss/wiki">Object Orientated CSS</a>
    </li>
</ul>
<h2>Features CSS Doesn&#8217;t Need</h2>
<h3>Variables</h3>
<blockquote>
<p>Variables allow you to specify widely used values in a single place and the re-use them throughout a stylesheet.</p>
</blockquote>
<p>Sounds great, right?</p>
<p>No.</p>
<p>If you write your CSS correctly there should be no &#8220;widely used values&#8221; in your code. <code>property: value</code> pairs should not be repeated in your code. If you need to use variables then it is a sign that your code isn&#8217;t structured correctly.</p>
<p>Take the following Sass code:</p>
<pre><code>$small: 12px;
.sidebar {
    background: #ccc;
    font-size: $small;
}
.permalink {
    border-top: 1px solid #ccc;
    color: #333;
    font-size: $small;
}</code></pre>
<pre><code>&lt;div class="sidebar"&gt;&lt;/div&gt;
&lt;div class="permalink"&gt;&lt;/div&gt;</code></pre>
<p>The value 12px is used a number of times throughout the code, so we&#8217;ve taken that value and stored it as a variable. That way when we need to change the value we only need to change the value in a single place. We could do the same thing using CSS just by creating a new <code>.small</code> class:</p>
<pre><code>.small {
    font-size: 12px;
}
.sidebar {
    background: #ccc;
}
.permalink {
    border-top: 1px solid #ccc;
    color: #333;
}</code></pre>
<pre><code>&lt;div class="sidebar small"&gt;&lt;/div&gt;
&lt;div class="permalink small"&gt;&lt;/div&gt;</code></pre>
<p>This doesn&#8217;t seem like much of an improvement. But what if you want the comment count to appear small too? If you do this using your variable in Sass you&#8217;ll need to add another class:</p>
<pre><code>$small: 12px;
.sidebar {
    background: #ccc;
    font-size: $small;
}
.permalink {
    border-top: 1px solid #ccc;
    color: #333;
    font-size: $small;
}
.comment-count {
    font-size: $small;
}</code></pre>
<pre><code>&lt;div class="comment-count"&gt;3 comments&lt;/div&gt;</code></pre>
<p>Now, if you had created a specific <code>.small</code> class you wouldn&#8217;t actually need to modify your CSS at all. You could just use the existing rules.</p>
<pre><code>.small {
    font-size: 12px;
}
.sidebar {
    background: #ccc;
}
.permalink {
    border-top: 1px solid #ccc;
    color: #333;
}</code></pre>
<pre><code>&lt;div class="small"&gt;3 comments&lt;/div&gt;</code></pre>
<p>As you can see, if you need to use variables then your CSS is only going to get more and more complicated over time. However, if you use smaller classes to reduce the repetition of <code>property: value</code> pairs then your CSS becomes more flexible and less likely to grow out of control.</p>
<h3>Mixins</h3>
<blockquote>
<p>Mixins allow you to embed all the properties of a class into another class by simply including the class name as one of its properties. It’s just like variables, but for whole classes.</p>
</blockquote>
<p>Like variables, mixins are unnecessary. If you need to use them it is a sign that your code is not structured correctly. Take the following Sass example for styling some buttons:</p>
<pre><code>@mixin button($background: #333, $size: 16px) {
    background: $background;
    border-radius: 3px;
    color: #fff;
    display: inline-block;
    font-size: $size;
    font-weight: bold;
    padding: 10px;
}
.button {
    @include button;
}
.submit-button {
    @include button(#0f0);
}
.small-button {
    @include button(#333, 12px);
}
.small-submit-button {
    @include button(#0f0, 12px);
}</code></pre>
<pre><code>&lt;button class="button"&gt;Ordinary Button&lt;/button&gt;
&lt;button class="submit-button"&gt;Submit button&lt;/button&gt;
&lt;button class="small-button"&gt;Small button&lt;/button&gt;
&lt;button class="small-submit-button"&gt;Small submit button&lt;/button&gt;</code></pre>
<p>And then here is the same thing written using CSS:</p>
<pre><code>.small {
    font-size: 12px;
}
.button {
    background: #333;
    border-radius: 3px;
    color: #fff;
    display: inline-block;
    font-size: 16px;
    font-weight: bold;
    padding: 10px;
}
.submit-button {
    background: #0f0;
}</code></pre>
<pre><code>&lt;button class="button"&gt;Ordinary Button&lt;/button&gt;
&lt;button class="button submit-button"&gt;Submit button&lt;/button&gt;
&lt;button class="button small"&gt;Small button&lt;/button&gt;
&lt;button class="button submit-button small"&gt;Small submit button&lt;/button&gt;</code></pre>
<p>In this example the pure CSS is smaller, easier to understand, and easier to maintain.</p>
<p>As you can see, by structuring your CSS correctly you can actually write much more terse code than you would using features like variables and mixins.</p>
<h3>Advanced Features</h3>
<p>Sass and LESS also have several advanced features such as mathematics and color manipulation. These features do have some benefits in terms of documenting your thought process in terms of design decisions, but if you want to document your thought process the real solution isn&#8217;t to throw mathematics or function calls into your CSS, but instead to use comments.</p>
<pre><code>.nav {
    margin-bottom: $vertical-rhythm * 2;
}</code></pre>
<pre><code>.nav {
    margin-bottom: 36px; /* Twice the line-height of body text */
}</code></pre>
<h2>Problems</h2>
<h3>Setting up a Development Environment</h3>
<p>Unlike CSS which works out of the box with any text editor or browser development tools, if you want to use a CSS preprocessor you will need to download some additional tools to get your development environment working. I haven&#8217;t found a text editor that plays nicely with Sass out of the box, and you also need to download a Firebug plugin to get Firebug looking at the correct files too.</p>
<p>This isn&#8217;t a huge problem, but when you&#8217;ve got to setup a development environment for a team of front-end developers, it&#8217;s just more steps that need to be documented and carried out to make sure everyone is able to work effectively.</p>
<h3>The Problem with Preprocessors</h3>
<p>This sounds basic, but I had a couple of problems where I&#8217;d make changes in my Sass files and the CSS rules weren&#8217;t being applied. The problem turned out being that the preprocessor was not running, so my changes to Sass files weren&#8217;t being applied to the compiled CSS files.</p>
<p>It&#8217;s not hard to remember to setup a CSS preprocessor to watch your stylesheets, but it&#8217;s just another thing that has to be done and another thing I might forget when I get into work in the morning. Being able to open my text editor and start coding without having to think about it is a very valuable thing.</p>
<h2>Conclusion</h2>
<p>While CSS preprocessors provide a lot of extra features on top of CSS, those features aren&#8217;t necessary if you write your code using the OOCSS approach.</p>
<p>What do you think? Are CSS preprocessors useful even if you use an OOCSS approach?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blakehaswell.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blakehaswell.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blakehaswell.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blakehaswell.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blakehaswell.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blakehaswell.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blakehaswell.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blakehaswell.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blakehaswell.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blakehaswell.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blakehaswell.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blakehaswell.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blakehaswell.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blakehaswell.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blakehaswell.wordpress.com&amp;blog=4711557&amp;post=36&amp;subd=blakehaswell&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blakehaswell.wordpress.com/2011/12/28/less-sass-more-oocss/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Blake</media:title>
		</media:content>
	</item>
		<item>
		<title>Long Lost Nephew of Suckerfish, Part Deux</title>
		<link>http://blakehaswell.wordpress.com/2009/03/20/long-lost-nephew-of-suckerfish-part-deux/</link>
		<comments>http://blakehaswell.wordpress.com/2009/03/20/long-lost-nephew-of-suckerfish-part-deux/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 01:33:25 +0000</pubDate>
		<dc:creator>Blake</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blakehaswell.wordpress.com/?p=29</guid>
		<description><![CDATA[I was asked to mockup and example of a horizontal version of my dropdown menu, and this inspired me to have another look at the code behind it and clean it up. One of the biggest limitations of the previous &#8230; <a href="http://blakehaswell.wordpress.com/2009/03/20/long-lost-nephew-of-suckerfish-part-deux/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blakehaswell.wordpress.com&amp;blog=4711557&amp;post=29&amp;subd=blakehaswell&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was asked to mockup and example of a horizontal version of my dropdown menu, and this inspired me to have another look at the code behind it and clean it up.</p>
<p>One of the biggest limitations of the previous version was that your menu was limited to 3 levels deep. The first thing I decided to change was to make the onfocus and onblur events call recursive functions, allowing you to have an infinitely deep menu and still have keyboard accessibility.</p>
<pre><code>anchor.onfocus = function() { tabOn(this.parentNode); }
anchor.onblur = function() { tabOff(this.parentNode); }

…

function tabOn(li) {
	if(li.nodeName == 'LI') {
		li.className = addClass(li);
		tabOn(li.parentNode.parentNode);
	}
}

function tabOff(li) {
	if(li.nodeName == 'LI') {
		li.className = removeClass(li);
		tabOff(li.parentNode.parentNode);
	}
}</code></pre>
<p>Beyond that the changes were mostly small. I moved the code to add and remove classes into their own functions, and generally cleaned up the code a little.</p>
<p>Also IE6 can&#8217;t deal with the <code>&gt;</code> selector so I needed to add a stylesheet for IE6 to make the drop-down play nicely over a number of levels. If you want more of fewer levels you can modify this code to suit:</p>
<pre><code>#nav li.hover ul ul,
#nav li.hover li.hover ul ul,
#nav li.hover li.hover li.hover ul ul,
#nav li.hover li.hover li.hover li.hover ul ul	{ margin-left: -9999px; }

#nav li.hover ul,
#nav li.hover li.hover ul,
#nav li.hover li.hover li.hover ul,
#nav li.hover li.hover li.hover li.hover ul	{ margin-left: 0; }</code></pre>
<p>Having a seperate stylesheet for IE6 also allowed me to clean up the CSS a lot, so this version is quite a lot cleaner.</p>
<p>Check out the new and improved version of the code, along with an example of a horizontal dropdown: <a href="http://blakehaswell.com/lab/dropdown/deux/">example</a>.</p>
<p>You can grab the source and use or modify it however you like: <a href="http://blakehaswell.com/lab/dropdown/deux/js/dropdown.js">JavaScript</a>, <a href="http://blakehaswell.com/lab/dropdown/deux/css/dropdown.css">CSS</a>, <a href="http://blakehaswell.com/lab/dropdown/deux/css/ie6.css">IE6 CSS</a>.</p>
<p>As always comments and questions are appreciated.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blakehaswell.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blakehaswell.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blakehaswell.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blakehaswell.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blakehaswell.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blakehaswell.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blakehaswell.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blakehaswell.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blakehaswell.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blakehaswell.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blakehaswell.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blakehaswell.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blakehaswell.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blakehaswell.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blakehaswell.wordpress.com&amp;blog=4711557&amp;post=29&amp;subd=blakehaswell&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blakehaswell.wordpress.com/2009/03/20/long-lost-nephew-of-suckerfish-part-deux/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Blake</media:title>
		</media:content>
	</item>
		<item>
		<title>Placing a background image in each corner</title>
		<link>http://blakehaswell.wordpress.com/2008/10/03/placing-a-background-image-in-each-corner/</link>
		<comments>http://blakehaswell.wordpress.com/2008/10/03/placing-a-background-image-in-each-corner/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 13:27:12 +0000</pubDate>
		<dc:creator>Blake</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Background]]></category>
		<category><![CDATA[Background Image]]></category>
		<category><![CDATA[CSS3]]></category>

		<guid isPermaLink="false">http://blakehaswell.wordpress.com/?p=23</guid>
		<description><![CDATA[I recently saw a discussion on CSS-D about multiple background images, and while it doesn’t exactly answer the question I thought I’d share a tip that some of you may find useful. At least until multiple backgrounds with CSS3 is &#8230; <a href="http://blakehaswell.wordpress.com/2008/10/03/placing-a-background-image-in-each-corner/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blakehaswell.wordpress.com&amp;blog=4711557&amp;post=23&amp;subd=blakehaswell&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently saw a <a href="http://archivist.incutio.com/viewlist/css-discuss/102000">discussion on CSS-D</a> about multiple background images, and while it doesn’t exactly answer the question I thought I’d share a tip that some of you may find useful. At least until <a href="http://www.css3.info/preview/multiple-backgrounds/">multiple backgrounds with CSS3</a> is properly supported.</p>
<p>So, what we want to do here is put a background image in each of the four corners of the body. The mark-up we need:</p>
<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
	&lt;head&gt;
		&lt;title&gt;Example: A background image in each corner&lt;/title&gt;
		&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
		&lt;link rel="stylesheet" type="text/css" href="css/style.css" /&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;div id="outer_container"&gt;
			&lt;div id="container"&gt;
			&lt;/div&gt;
		&lt;/div&gt;
	&lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>Unfortunately the extra DIVs are required as a hook for the background images, but we can reduce the number required down to two by using the HTML element and the BODY element as hooks for two of the images.</p>
<p>And the CSS:</p>
<pre><code>*			{ margin: 0; padding: 0; }
html			{ background: #fff url(../images/top_left.gif) top left no-repeat; height: 100%; }
body			{ background: url(../images/top_right.gif) top right no-repeat; height: 100%; }
#outer_container	{ background: url(../images/bottom_left.gif) bottom left no-repeat; height: 100%; }
#container		{ background: url(../images/bottom_right.gif) bottom right no-repeat; min-height: 100%; _height: 100%; }</code></pre>
<p>The only thing really to note is that <code>_height: 100%;</code> is a hack for IE6 to mimic the behaviour of <code>min-height: 100%;</code>, and will cause the stylesheet to fail validation. You can put that in an IE only stylesheet if that sort of thing bothers you.</p>
<p><a href="http://www.blakehaswell.com/lab/background-images/">Here is our working example</a>. This technique has been tested to work in Firefox, Opera, Safari for Windows, IE7, and IE6.</p>
<p>Also, just as a note this technique can cause some freaky results when page-zoom is used in IE7, but to a lesser or greater extent this sort of thing will always choke a little in IE7 with page-zoom.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blakehaswell.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blakehaswell.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blakehaswell.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blakehaswell.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blakehaswell.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blakehaswell.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blakehaswell.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blakehaswell.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blakehaswell.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blakehaswell.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blakehaswell.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blakehaswell.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blakehaswell.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blakehaswell.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blakehaswell.wordpress.com&amp;blog=4711557&amp;post=23&amp;subd=blakehaswell&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blakehaswell.wordpress.com/2008/10/03/placing-a-background-image-in-each-corner/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Blake</media:title>
		</media:content>
	</item>
		<item>
		<title>OMFG w00t!</title>
		<link>http://blakehaswell.wordpress.com/2008/09/15/omfg-w00t/</link>
		<comments>http://blakehaswell.wordpress.com/2008/09/15/omfg-w00t/#comments</comments>
		<pubDate>Sun, 14 Sep 2008 14:52:20 +0000</pubDate>
		<dc:creator>Blake</dc:creator>
				<category><![CDATA[Formula 1]]></category>
		<category><![CDATA[Motorsport]]></category>
		<category><![CDATA[Italian GP]]></category>
		<category><![CDATA[Minardi]]></category>
		<category><![CDATA[Scuderia Torro Rosso]]></category>
		<category><![CDATA[Sebastian Vettel]]></category>

		<guid isPermaLink="false">http://blakehaswell.wordpress.com/?p=13</guid>
		<description><![CDATA[<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blakehaswell.wordpress.com&amp;blog=4711557&amp;post=13&amp;subd=blakehaswell&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img src="http://blakehaswell.files.wordpress.com/2008/09/vettel.jpg?w=500&#038;h=278" alt="Sebastian Vettel dominated the Italian GP to win for Torro Rosso!" width="500" height="278" /></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/blakehaswell.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/blakehaswell.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blakehaswell.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blakehaswell.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blakehaswell.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blakehaswell.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blakehaswell.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blakehaswell.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blakehaswell.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blakehaswell.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blakehaswell.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blakehaswell.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blakehaswell.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blakehaswell.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blakehaswell.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blakehaswell.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blakehaswell.wordpress.com&amp;blog=4711557&amp;post=13&amp;subd=blakehaswell&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blakehaswell.wordpress.com/2008/09/15/omfg-w00t/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Blake</media:title>
		</media:content>

		<media:content url="http://blakehaswell.files.wordpress.com/2008/09/vettel.jpg" medium="image">
			<media:title type="html">Sebastian Vettel dominated the Italian GP to win for Torro Rosso!</media:title>
		</media:content>
	</item>
		<item>
		<title>Long Lost Nephew of Suckerfish</title>
		<link>http://blakehaswell.wordpress.com/2008/09/04/long-lost-nephew-of-suckerfish/</link>
		<comments>http://blakehaswell.wordpress.com/2008/09/04/long-lost-nephew-of-suckerfish/#comments</comments>
		<pubDate>Thu, 04 Sep 2008 13:26:39 +0000</pubDate>
		<dc:creator>Blake</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[Dropdown Menu]]></category>
		<category><![CDATA[Progressive Enhancement]]></category>
		<category><![CDATA[Usability]]></category>

		<guid isPermaLink="false">http://blakehaswell.wordpress.com/?p=3</guid>
		<description><![CDATA[I needed to create a CSS-based drop-down list that would work cross-browser and had some extra features for better usability including a mouse-off delay and keyboard accessibility. I was very familiar with the suckerfish menu, but it didn’t meet my &#8230; <a href="http://blakehaswell.wordpress.com/2008/09/04/long-lost-nephew-of-suckerfish/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blakehaswell.wordpress.com&amp;blog=4711557&amp;post=3&amp;subd=blakehaswell&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I needed to create a CSS-based drop-down list that would work cross-browser and had some extra features for better usability including a mouse-off delay and keyboard accessibility.</p>
<p>I was very familiar with the <a href="http://www.alistapart.com/articles/dropdowns">suckerfish menu</a>, but it didn’t meet my needs to I decided to scrap it and start from scratch. So here I’ll go through what I came up with.</p>
<p>Our HTML structure is the standard nested list format that we all know and love:</p>
<pre><code>&lt;ul id="nav"&gt;
	&lt;li&gt;
		&lt;a href="#"&gt;Home&lt;/a&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;a href="#"&gt;News&lt;/a&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;a href="#"&gt;Photos&lt;/a&gt;
		&lt;ul&gt;
			&lt;li&gt;
				&lt;a href="#"&gt;Reader Shots&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#"&gt;Wallpapers&lt;/a&gt;
				&lt;ul&gt;
					&lt;li&gt;
						&lt;a href="#"&gt;800 x 600&lt;/a&gt;
					&lt;/li&gt;
					&lt;li&gt;
						&lt;a href="#"&gt;1024 x 768&lt;/a&gt;
					&lt;/li&gt;
					&lt;li&gt;
						&lt;a href="#"&gt;1280 x 1024&lt;/a&gt;
					&lt;/li&gt;
				&lt;/ul&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#"&gt;Photo Galleries&lt;/a&gt;
			&lt;/li&gt;
		&lt;/ul&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;a href="#"&gt;Videos&lt;/a&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;a href="#"&gt;Results&lt;/a&gt;
		&lt;ul&gt;
			&lt;li&gt;
				&lt;a href="#"&gt;National&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#"&gt;International&lt;/a&gt;
			&lt;/li&gt;
		&lt;/ul&gt;
	&lt;/li&gt;
&lt;/ul&gt;</code></pre>
<p>Once we have our HTML structure the first thing we’re going to do is set the styles for how the menus should look when they’re expanded. In this case we’re going with some very simple styles, but you can make this as complicated as you like.</p>
<pre><code>#nav,
#nav li ul				{ list-style: none; margin: 0; padding: 0; width: 150px; }
#nav li					{ padding: 0 3px 3px 0; position: relative; }
#nav li a				{ border: 1px solid #000; display: block; text-decoration: none; width: 145px; }

#nav li ul				{ left: 150px; position: absolute; top: 0; }
#nav li a				{ background: #fff; color: #000; }</code></pre>
<p>Example 1: <a href="http://www.blakehaswell.com/lab/dropdown/stage_1/">The basic structure for our menu, but no functionality yet</a></p>
<p>Now <a href="http://www.blakehaswell.com/lab/dropdown/stage_1/">we have our menu in place</a> we’ve got to get it acting like a dropdown. We’re using a negative margin-left to achieve this, and then setting the margin to 0 when the list item is hovered over:</p>
<pre><code>#nav li:hover ul li ul,
#nav li ul				{ margin-left: -9999px; }

#nav li ul li ul,
#nav li:hover ul,
#nav li ul li:hover ul			{ margin-left: 0; }

#nav li a,
#nav li:hover ul li a,
#nav li ul li:hover ul li a		{ background: #fff; color: #000; }

#nav li:hover a,
#nav li a:hover,
#nav li ul li:hover a,
#nav li ul li a:hover,
#nav li ul li:hover ul li:hover a,
#nav li ul li:hover ul li a:hover	{ background: #000; color: #fff; }</code></pre>
<p>Example 2: <a href="http://www.blakehaswell.com/lab/dropdown/stage_2/">Basic CSS Dropdown Menu</a></p>
<p>The next step is to make it keyboard accessible in modern browsers (everything except IE). We can do this by using a combination of the :focus pseudo class and the + combinator to provide some basic keyboard functionality. It isn’t relevant yet, but I’ve seperated selectors using the + combinator from other selectors because IE6 ignores all of the selectors in a list if one is using the + combinator.</p>
<pre><code>#nav li:hover ul li ul,
#nav li ul				{ margin-left: -9999px; }
#nav li a:focus + ul li ul		{ margin-left: -9999px; }

#nav li ul li ul,
#nav li:hover ul,
#nav li ul li:hover ul,
#nav li.hover ul li a:focus,
#nav li ul li.hover ul li a:focus	{ margin-left: 0; }
#nav li a:focus + ul,
#nav li ul li a:focus + ul		{ margin-left: 0; }

#nav li a,
#nav li:hover ul li a,
#nav li ul li:hover ul li a		{ background: #fff; color: #000; }

#nav li:hover a,
#nav li a:hover,
#nav li a:focus,
#nav li a:active,
#nav li ul li:hover a,
#nav li ul li a:hover,
#nav li ul li:hover ul li:hover a,
#nav li ul li:hover ul li a:hover	{ background: #000; color: #fff; }

#nav li ul li a:focus,
#nav li ul li ul li a:focus		{ margin-left: 9999px; }</code></pre>
<p>As you can see in our <a href="http://www.blakehaswell.com/lab/dropdown/stage_3/">example page</a> there is a lot to be desired for keyboard users, but it’s a good start. We will use JavaScript to provide better usability for keyboard users, but we’ll get to that later.</p>
<p>Example 3: <a href="http://www.blakehaswell.com/lab/dropdown/stage_3/">CSS-based dropdown menu that is keyboard accessible in modern browsers</a></p>
<p>If you’ve had a look at any of these examples in IE6 you probably will have seen that the menu doesn’t work. At all. We need to use JavaScript to fix our IE6 issues, so while we’re at it let’s add some usability aids, such as a mouse-off delay.</p>
<p>All of this is done by the function below. It is completely parameterised so you can apply it to any number of dropdown lists and change the timing, etc.</p>
<pre><code>//	dropDownId	string	ID of the UL containing the drop down
//	hoverClass	string	Class to be applied to the LIs on mouse over
//	mouseOffDelay	int	Delay from when the mouse is lifted from the drop down until hoverClass is removed (in milliseconds)
function drop_down(dropDownId, hoverClass, mouseOffDelay) {
	if(dropDown = document.getElementById(dropDownId)) {
		var listItems = dropDown.getElementsByTagName('li');
		for(var i = 0; i &lt; listItems.length; i++) {
			listItems[i].onmouseover = function() {
				this.className += ' ' + hoverClass;
			}
			listItems[i].onmouseout = function() {
				var that = this;
				setTimeout(function() {
					that.className = that.className.replace(hoverClass, "")
				}, mouseOffDelay);
				this.className = that.className;
			}
		}
	}
}</code></pre>
<p>And we call the function like so:</p>
<pre><code>drop_down('nav', 'hover', 250);</code></pre>
<p>In our examples we have used Simon Willison’s great <a href="http://simonwillison.net/2004/May/26/addLoadEvent/">Add Load Event</a> function to call the function on page load, however you can use any method you like.</p>
<p>Now we need to change our CSS to use our new .hover class:</p>
<pre><code>#nav li:hover ul li ul,
#nav li ul,
#nav li.hover ul li ul			{ margin-left: -9999px; }
#nav li a:focus + ul li ul		{ margin-left: -9999px; }

#nav li.hover ul,
#nav li ul li ul,
#nav li ul li.hover ul,
#nav li:hover ul,
#nav li ul li:hover ul,
#nav li.hover ul li a:focus,
#nav li ul li.hover ul li a:focus	{ margin-left: 0; }
#nav li a:focus + ul,
#nav li ul li a:focus + ul		{ margin-left: 0; }

#nav li a,
#nav li:hover ul li a,
#nav li.hover ul li a,
#nav li ul li:hover ul li a,
#nav li ul li.hover ul li a		{ background: #fff; color: #000; }

#nav li:hover a,
#nav li.hover a,
#nav li a:hover,
#nav li a:focus,
#nav li a:active,
#nav li ul li:hover a,
#nav li ul li.hover a,
#nav li ul li a:hover,
#nav li ul li:hover ul li:hover a,
#nav li ul li.hover ul li.hover a,
#nav li ul li:hover ul li a:hover	{ background: #000; color: #fff; }</code></pre>
<p>Example 4: <a href="http://www.blakehaswell.com/lab/dropdown/stage_4/">JavaScript enhancements allow IE6 users to use the menu and adds a usability improvement</a></p>
<p>The final piece of the puzzle is to make our menu keyboard accessible for all browsers and more usable to-boot. We do this by mimicking the effect of hovering of a list-item when you are focused on it’s child anchor. Inside our loop we’ll insert the following piece of script:</p>
<pre><code>var anchor = listItems[i].getElementsByTagName('a');
anchor = anchor[0];
anchor.onfocus = function() {
	if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == 'LI') {
		this.parentNode.parentNode.parentNode.parentNode.parentNode.className += ' ' + hoverClass;
	}
	if(this.parentNode.parentNode.parentNode.nodeName == 'LI') {
		this.parentNode.parentNode.parentNode.className += ' ' + hoverClass;
	}
	if(this.parentNode.nodeName == 'LI') {
		this.parentNode.className += ' ' + hoverClass;
	}
}
anchor.onblur = function() {
	if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == 'LI') {
		this.parentNode.parentNode.parentNode.parentNode.parentNode.className = this.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(hoverClass, "");
	}
	if(this.parentNode.parentNode.parentNode.nodeName == 'LI') {
		this.parentNode.parentNode.parentNode.className = this.parentNode.parentNode.parentNode.className.replace(hoverClass, "");
	}
	if(this.parentNode.nodeName == 'LI') {
		this.parentNode.className = this.parentNode.className.replace(hoverClass, "");
	}
}</code></pre>
<p>This script finds the first anchor and assigns onfocus and onblur events to it (the keyboard equivalent to onmouseover and onmouseout, except that it can only be applied to focusable elements i.e. links and form controls).</p>
<p>When we tab onto a link we want to assign our hoverClass to the anchors parent LI, and depending how deep it is we want to apply hoverClass to it’s great grandparent LI and it’s great great great grandparent LI. This allows us to style all of it’s parents, helping to give keyboard users a better indication of where they are.</p>
<p>Example 5: <a href="http://www.blakehaswell.com/lab/dropdown/stage_5/">Final JavaScript enhancements make the menu more accessible to keyboard users on all browsers</a></p>
<p>Please grab the finished <a href="http://www.blakehaswell.com/lab/dropdown/stage_5/css/drop_down.css">CSS</a> and <a href="http://www.blakehaswell.com/lab/dropdown/stage_5/js/drop_down.js">JavaScript</a> files.</p>
<p>Check out the finished product, kick the tyres, and let me know what you think. Feel free to use abuse and modify as you need. Attribution is always appreciated.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/blakehaswell.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/blakehaswell.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blakehaswell.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blakehaswell.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blakehaswell.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blakehaswell.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blakehaswell.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blakehaswell.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blakehaswell.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blakehaswell.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blakehaswell.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blakehaswell.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blakehaswell.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blakehaswell.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blakehaswell.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blakehaswell.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blakehaswell.wordpress.com&amp;blog=4711557&amp;post=3&amp;subd=blakehaswell&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blakehaswell.wordpress.com/2008/09/04/long-lost-nephew-of-suckerfish/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Blake</media:title>
		</media:content>
	</item>
	</channel>
</rss>
