<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Komodo Media &#187; techniques</title>
	<atom:link href="http://www.komodomedia.com/tags/techniques/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.komodomedia.com</link>
	<description>blog, webdesign, illustration &#38; newsk00l javascript</description>
	<lastBuildDate>Wed, 18 Jan 2012 14:43:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CSS Sliding Sprite Windows</title>
		<link>http://www.komodomedia.com/blog/2008/09/css-sliding-sprite-windows/</link>
		<comments>http://www.komodomedia.com/blog/2008/09/css-sliding-sprite-windows/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 18:03:40 +0000</pubDate>
		<dc:creator>Rogie</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Nerdlab]]></category>
		<category><![CDATA[techniques]]></category>
		<category><![CDATA[xHTML]]></category>

		<guid isPermaLink="false">http://www.komodomedia.com/?p=277</guid>
		<description><![CDATA[<img src="http://d2dnrmagaqciul.cloudfront.net/wp-content/uploads/2008/09/sliding_banner.jpg" alt="" title="sliding_banner" width="460" height="180" class="alignnone size-full wp-image-278" />
I want to share a CSS technique I've used alot. I'm sure that you have seen CSS sprite techniques that utilize changing background position on hover to change a link's state.  Also, they have the added benefit of keeping from loading images on hover, limiting lag. This technique is very similar, but works like a charm for IE6 and PNG images.  I know this may be a <a href="http://www.urbandictionary.com/define.php?term=moo+point">moo point </a>at this stage, because IE6 is on the outs, but still works beautifully as a technique.]]></description>
			<content:encoded><![CDATA[<p><img src="http://d2dnrmagaqciul.cloudfront.net/wp-content/uploads/2008/09/sliding_banner.jpg" alt="" title="sliding_banner" width="460" height="180" class="alignnone size-full wp-image-278" /></p>
<div class="post_info">
<ul>
<li>
<li><a class="download" href="http://www.komodomedia.comwp-content/uploads/2008/09/css_sliding_sprite_windows.zip">Download Example</a></li>
<li><a class="preview" href="http://d2dnrmagaqciul.cloudfront.net/samples/css_sliding_sprite_windows/index.html">Preview/Code</a></li>
</ul>
</div>
<p>I want to share a CSS technique I&#8217;ve used alot. I&#8217;m sure that you have seen CSS sprite techniques that utilize changing background position on hover to change a link&#8217;s state.  Also, they have the added benefit of keeping from loading images on hover, limiting lag. This technique is very similar, but works like a charm for IE6 and PNG images.  I know this may be a <a href="http://www.urbandictionary.com/define.php?term=moo+point">moo point </a>at this stage, because IE6 is on the outs, but still works beautifully as a technique.</p>
<p>Let&#8217;s jump right in, as I don&#8217;t have a lot of my Labor day to give.</p>
<p>First, as always, I want to preview this thing and see what it does. Here&#8217;s your preview:</p>
<link rel="stylesheet" href="http://d2dnrmagaqciul.cloudfront.net/samples/css_sliding_sprite_windows/index.css" type="text/css" media="all" />
<a target="donate" style="margin:0 auto;" href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&#038;business=rogie%40komodomedia%2ecom&#038;item_name=Donate%20a%20Java&#038;amount=4%2e00&#038;no_shipping=0&#038;no_note=1&#038;tax=0&#038;currency_code=USD&#038;lc=US&#038;bn=PP%2dDonationsBF&#038;charset=UTF%2d8" id="buyme_coffee"><span>Buy me a coffee</span></a><br />
You get the picture. Hover it, click it, etc&#8230;the button has different states.</p>
<h3>Aight, the meat and potatoes: the XHTML</h3>
<p>So, the markup is pretty simple. It&#8217;s basically a link with a span in it. Check it:</p>
<p><code>&lt;a href="..." id="buyme_coffee"&gt;<br />
   &lt;span&gt;Buy me a coffee&lt;/span&gt;<br />
&lt;/a&gt;</code></p>
<h3>How it works</h3>
<p>Before looking at the CSS, it helps to know how it works. Think of it as a window to a larger canvas behind it. It&#8217;s easy to think of it in terms of the two elements:</p>
<ul>
<li><strong>The window</strong>: The <code class="inline"> A </code> tag</li>
<li><strong>The canvas</strong>: The <code class="inline"> SPAN </code> tag</li>
</ul>
<p>The window only shows a portion (a view) of the canvas.  The canvas can be any size.  By changing the position of the canvas, you can pan a different portion of it into the window.  The window is fixed width, fixed height, and any overflowing content is hidden. This way, only the portion of the canvas in the window view is visible.</p>
<h3>The CSS</h3>
<p><code>#buyme_coffee,<br />
#buyme_coffee span{<br />
	display:block;<br />
	width:160px;<br />
	height:40px;<br />
	position:relative;<br />
	overflow: hidden;<br />
}<br />
#buyme_coffee span{<br />
	height:120px;<br />
	background: url(coffee_button.png) 0 0 no-repeat;<br />
	text-indent:-9000px;<br />
}<br />
#buyme_coffee:hover span{<br />
	top:-40px;<br />
}<br />
#buyme_coffee:active span,<br />
#buyme_coffee:focus span{<br />
	top:-80px;<br />
}</code></p>
<p><strong>The first selector </strong>targets two tags, the <code class="inline">#buyme_coffee</code> link and the <code class="inline">#buyme_coffee span</code> span inside the link.  I&#8217;m doubling up the rules by targeting both tags because both tags share quite a few similar tags. As for the rules that are different, I&#8217;ll correct in the next selector. </p>
<p>This first selector sets both <code class="inline">A</code> tag and <code class="inline">SPAN</code> tags to block (since they are inline by default), sets the width and height, and then sets the overflow to hidden.  The <code class="inline">overflow:hidden</code> here is the key. This causes the <code class="inline">A</code> tag to act as a window that only views the content in its height x width box.  All other content is simply cutoff or put away from view.</p>
<p><strong>The second selector</strong>, <code class="inline">#buyme_coffee span</code>, resets the height to the height of the background image, which is larger than the viewport (<code class="inline">A</code> tag), but gets cutoff from view.  The <code class="inline">text-indent:-9000px</code> is a cheap way of shoving the text off the screen so that this text is replaced by the background image. The background image contains the three states we want: Default, Hover and Focus/Active.  Here&#8217;s a preview of that background image:<br />
<img src="http://www.komodomedia.comwp-content/uploads/2008/09/coffee_button.png" alt="CSS sliding sprite window button image"/></p>
<p>You probably guessed it.  The top image will show as default.</p>
<p>K, we&#8217;re almost done.  <strong>The third and fourth selectors</strong> target the <code class="inline">:hover</code> and the <code class="inline">:active</code> and <code class="inline">:focus</code> states respectively.  This is uber simple.  When the link (or window) is hovered, push the top of the span (or canvas) up by 40px, showing the hover state.  When the link is active or focused, push the span up by 80px, revealing the active state.</p>
<p>That&#8217;s it!  So why is this better than just panning the background position you ask? Good question.  I started using this method when I needed to make the background an alpha-transparent PNG, which as you know, doesn&#8217;t display correctly unless you use an <a href="http://www.komodomedia.com/blog/2007/11/css-png-image-fix-for-ie/">IE alpha image loader filter</a>, which as you know doesn&#8217;t play nicely with background image positions.  With this method, you can apply an alpha image loader filter to the <code class="inline">span</code> element and it works like a charm.</p>
<p>Hope you enjoy. Cheers!</p>
<p><strong>Update:</strong> Based on @Justin&#8217;s suggestion, I&#8217;ve included some modified CSS below to show this technique sans the a <code class="inline">text-indent:-9000px</code> for screen reader friendliness. A <a href="http://d2dnrmagaqciul.cloudfront.net/samples/css_sliding_sprite_windows/index2.html">demo of the modified CSS can be seen here.</a></p>
<p><code>#buyme_coffee,<br />
#buyme_coffee span{<br />
	display:block;<br />
	width:160px;<br />
	height:40px;<br />
	position:relative;<br />
	overflow: hidden;<br />
}<br />
#buyme_coffee span{<br />
	height:140px;<br />
	background: url(coffee_button.png) 0 0 no-repeat;<br />
	line-height: 20px;<br />
	white-space: nowrap;<br />
	top:-20px;<br />
}<br />
#buyme_coffee:hover span{<br />
	top:-60px;<br />
}<br />
#buyme_coffee:active span,<br />
#buyme_coffee:focus span{<br />
	top:-100px;<br />
}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.komodomedia.com/blog/2008/09/css-sliding-sprite-windows/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: komodomedia.com @ 2012-02-10 14:32:12 by W3 Total Cache -->
