<?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>Firman Wandayandi &#187; CSS</title>
	<atom:link href="http://firmanw.com/tag/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://firmanw.com</link>
	<description></description>
	<lastBuildDate>Sun, 10 Jan 2010 10:56:36 +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>Link with CSS Background Overlay</title>
		<link>http://firmanw.com/tutorial/link-with-css-background-overlay/</link>
		<comments>http://firmanw.com/tutorial/link-with-css-background-overlay/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 22:02:38 +0000</pubDate>
		<dc:creator>Firman</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Inspiration]]></category>
		<category><![CDATA[Trends]]></category>

		<guid isPermaLink="false">http://firmanw.com/?p=20</guid>
		<description><![CDATA[While I&#8217;m visiting Komodomedia, there is an interesting small unique thing I ever found. It&#8217;s a Last.fm bar on the footer of page which is decorated as the CDs! Is it fancy though? Did you wondering how to make it? No, he didn&#8217;t draw it on Photoshop. It&#8217;s a CSS trick, I don&#8217;t know the [...]]]></description>
			<content:encoded><![CDATA[<p>While I&#8217;m visiting <a href="http://komodomedia.com/">Komodomedia</a>, there is an interesting small unique thing I ever found. It&#8217;s a <a href="http://last.fm/">Last.fm</a> bar on the footer of page which is decorated as the CDs! Is it fancy though? Did you wondering how to make it? No, he didn&#8217;t draw it on Photoshop. It&#8217;s a CSS trick, I don&#8217;t know the exactly trick used by <a href="http://twitter.com/rogieking">Rogie</a> and thanks to him, but all we need it&#8217;s an empty span floating over the cover art and apply the background image overlay. This trick has been tested on most popular browser: Firefox, Safari, Opera, Internet Explorer 7 even Internet Explorer 6. Continue to read the rest of this article to find out how and if you already knew how to do it or just have a better solution, feel free to leave a comment.</p>
<p><span id="more-20"></span></p>
<p><img class="aligncenter size-full wp-image-55" title="linkwithcssoverlay_sshoot" src="http://firmanw.com/wp-content/uploads/2008/11/linkwithcssoverlay_sshoot.jpg" alt="linkwithcssoverlay_sshoot" width="580" height="160" /></p>
<p><a href="http://labs.firmanw.com/tutorial/link-with-css-background-overlay/">Check out the demo</a> or <a href="http://firmanw.com/wp-content/uploads/2008/11/link-with-css-overlay.zip">Download demo ZIP</a></p>
<h3>How does this work?</h3>
<p><img class="alignright size-full wp-image-56" title="illus_cdoverlay" src="http://firmanw.com/wp-content/uploads/2008/11/illus_cdoverlay.png" alt="illus_cdoverlay" width="200" height="100" />The trick is &#8220;simple enough&#8221;. Basically we are just doing PNG alpha transparency overlay over the cover art. So the first thing we need to find the right CD image or you may also draw by your own. Don&#8217;t forget to make it transparent enough until you can see the cover art behind the CD, whatever the size you like but keep it feet the cover art. I have drawn it and the PSD also included in <a href="http://firmanw.com/wp-content/uploads/2008/11/link-with-css-overlay.zip">Download demo ZIP</a>, so you can change the background color as you need.</p>
<h3>The Markup</h3>
<p>It&#8217;s just like usual floating unordered list block, but add a &lt;span&gt; <span class="strike">before</span> after the image add a <span style="color:#ff3300;">&amp;nbsp;</span> inside to make it semantic.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Dido: No Angel&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.last.fm/music/Dido/No+Angel&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://userserve-ak.last.fm/serve/126/16070125.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cover&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;80&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;80&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span>&gt;</span> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span></pre></div></div>

<p>We use that span in order to overlay the cover art with the PNG background.</p>
<h3>Styling</h3>
<p>The key is <span style="color:#ff3300">a { position: relative; }</span> and <span style="color:#ff3300">a span { position: absolute; }</span>.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#music</span> a <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#music</span> a span <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/cd.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>You may <a href="http://labs.firmanw.com/tutorial/link-with-css-background-overlay/">check out the demo</a>.</p>
<h3>PNG color correction on IE 6/7</h3>
<p>Since IE considered gamma for PNG, the image and background color looks different. I have tried the scripting way to fix it but doesn&#8217;t work so the next solution is <a href="http://entropymine.com/jason/tweakpng/">TweakPNG</a>. Just open your file with TweakPNG, remove the gamma metadata and save.</p>
<p><img class="aligncenter size-full wp-image-58" title="tweakpng" src="http://firmanw.com/wp-content/uploads/2008/11/tweakpng.jpg" alt="tweakpng" width="580" height="196" /></p>
<h3>Make it work on IE 6</h3>
<p>You may leave this section if you won&#8217;t care about IE6 user.</p>
<h4>1. PNG alpha transparency</h4>
<p>Here we go again the legendary lack of IE 6, the PNG alpha transparency on PNG-24. <span class="strike">I&#8217;m using IE PNG Alpha Fix v 1.0 by TwinHelix and add the following piece of code.</span> Well simply just add this piece of code to the Stylesheet:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&lt;!--<span style="color: #00AA00;">&#91;</span>if lt IE <span style="color: #cc66cc;">7</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span>
&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
<span style="color: #cc00cc;">#music</span> a span <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
  filter<span style="color: #3333ff;">:progid</span><span style="color: #3333ff;">:DXImageTransform</span><span style="color: #6666ff;">.Microsoft</span>.AlphaImageLoader<span style="color: #00AA00;">&#40;</span>src<span style="color: #00AA00;">=</span><span style="color: #ff0000;">'images/cdoverlay.png'</span><span style="color: #00AA00;">,</span> sizingMethod<span style="color: #00AA00;">=</span><span style="color: #ff0000;">'crop'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span> 
&lt;/style<span style="color: #00AA00;">&gt;</span>
&lt;!--<span style="color: #00AA00;">&#91;</span>endif<span style="color: #00AA00;">&#93;</span>--<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p class="strike">In case you want to use other script, I tried few jquery plugins in purpose for PNG fix like <a href="http://jquery.andreaseberhard.de/pngFix/">jquery.pngFix.js by Andreas</a> and <a href="http://plugins.jquery.com/project/iepngfix">IE PNG Fix by Paul</a> but somehow it don&#8217;t work at all while handling the background on mouse over event. The last one is <a href="http://jquery.khurshid.com/ifixpng.php">jQuery.ifixpng</a> by Kush M and it&#8217;s work!</p>
<p>Why if block instead of <span style="color:#ff3300;">* html #music a span { &#8230; }</span>? The CSS will be a valid one.</p>
<h4>2. Handling the mouse over event</h4>
<p>IE 6 doesn&#8217;t recognize the Element hover (mouse over) event except for a Link, so required to add  <span class="strike">javascript stuff</span> a little more CSS tricks for it. I&#8217;m done with <span class="strike">helped by <a href="http://jquery.com/">jQuery</a></span> the great Paul Boutin&#8217;s advice. Here is it the detail explanation:</p>
<p>First we make the <span style="color:#ff3300;">&lt;a&gt;</span> and <span style="color:#ff3300;">&lt;span&gt;</span> have a fixed width as the background we have.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#music</span> a<span style="color: #00AA00;">,</span>
<span style="color: #cc00cc;">#music</span> a span <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">80px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Make the <span style="color:#ff3300;">&lt;a&gt;</span> have a fixed height to feet the background we wish to overlaying and mark the height property as important to force the element feet into the height, optionally we may also add overflow property as hidden to avoid element overflow.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#music</span> a <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">80px</span> !important<span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Here we make the <span style="color:#ff3300;">&lt;span&gt;</span> fixed to the &#8220;real&#8221; background height and place it absolutely at the top left of parent element (<span style="color:#ff3300;">&lt;a&gt;</span>).</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#music</span> a span <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">160px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Now we&#8217;re about to handling the hover event. At the <span style="color:#ff3300;">a:hover</span> we need to set the background position to left-bottom, so when mouse over triggered the background move to bottom position and display our second background. But we need also shift the  <span style="color:#ff3300;">span</span> position to blind spot area in order to make our second background visible. See how important the previous steps?</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#music</span> a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#music</span> a<span style="color: #3333ff;">:hover </span>span <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-80px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>This is the illustration about what happened above.</p>
<p><img class="aligncenter size-full wp-image-59" title="hover_handling_illustration" src="http://firmanw.com/wp-content/uploads/2008/11/hover_handling_illustration.png" alt="hover_handling_illustration" width="592" height="280" /></p>
<p>Credit to Paul Boutin, thanks.</p>
<h3>The last thing</h3>
<p>Another IE problematic, the cursor won&#8217;t change to hand when you move to the CD link so we need to add another line to the stylesheet</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&lt;!--<span style="color: #00AA00;">&#91;</span>if IE<span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&gt;</span>
&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
<span style="color: #cc00cc;">#music</span> a span <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> hand<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&lt;!--<span style="color: #00AA00;">&#91;</span>endif<span style="color: #00AA00;">&#93;</span>--<span style="color: #00AA00;">&gt;</span></pre></div></div>

<h3>Limitations</h3>
<ul>
<li class="strike">IE PNG hack and javascript stuff is required to make it fully work on IE 6.</li>
<li>TweakPNG is required to remove the gamma metadata in order to archived the color correction on IE.</li>
<li>For the best result you need to discovering over the image transparency before applying the background image overlay.</li>
</ul>
<p>I&#8217;m apologized about my poor english. Just leave a comment if you have a question, I will try my best to answer it.</p>
]]></content:encoded>
			<wfw:commentRss>http://firmanw.com/tutorial/link-with-css-background-overlay/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
