<?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>Developer Oracles &#187; sprites</title>
	<atom:link href="http://devoracles.com/tag/sprites/feed" rel="self" type="application/rss+xml" />
	<link>http://devoracles.com</link>
	<description></description>
	<lastBuildDate>Sun, 21 Mar 2010 11:05:37 +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 taken to extreme &#8211; The sprite</title>
		<link>http://devoracles.com/css-taken-to-extreme-the-sprite/471</link>
		<comments>http://devoracles.com/css-taken-to-extreme-the-sprite/471#comments</comments>
		<pubDate>Tue, 28 Oct 2008 19:16:48 +0000</pubDate>
		<dc:creator>Gary Illyes</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[sprite]]></category>
		<category><![CDATA[sprites]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://devoracles.com/?p=471</guid>
		<description><![CDATA[No, not the drink nor a fairy. I talk about a CSS technique which has been borrowed from the game developers if I&#8217;m not mistaken, but correct me if I&#8217;m wrong; since games appeared first and not CSS I guess this is the situation. The sprites in computer graphics are images which are moved across [...]]]></description>
			<content:encoded><![CDATA[<p>No, not the drink nor a fairy. I talk about a CSS technique which has been borrowed from the game developers if I&#8217;m not mistaken, but correct me if I&#8217;m wrong; since games appeared first and not CSS I guess this is the situation. The sprites in computer graphics are images which are moved across the screen to form a larger scale image. Uhh, I don&#8217;t understand! Read further and I explain.</p>
<p>In short, what&#8217;s this all about: I&#8217;m almost sure everybody realizes that nowadays every website has in its structure some kind of image, either for navigation, for background, for borders, anything, but today a website can&#8217;t look like back in &#8216;95, so the images has been brought on the scene to make the websites look better. The images which appear in the layout of a website are controlled by CSS. So, let&#8217;s say you have a website which has a cool background, every link has its own background image, you have cool borders, rounded corners. How would you do that in CSS? Somehow like this:</p>
<pre name="code" class="css">
#bg{
background:url(bg_img.jpg) repeat-y center;
}

#wrap{
margin: 0 auto;
width:700px;
background:url(wrap_bg_img.jpg) repeat-y center;
}

.home a{
display:block;
width:25px;
height:25px;
background:url(home_bg_img.jpg) no-repeat center;
}

.about a{
display:block;
width:25px;
height:25px;
background:url(about_bg_img.jpg) no-repeat center;
}
</pre>
<p>As you see above, each element has its own image. Each image is, let&#8217;s say 3kb. So what happens when someone loads this page? The end-users&#8217; browser will open 4 connections to the webserver, and will request each image one-by-one. So, there is time spent to open and close these connections. In addition, there is 12kb of data requested.<br />
What if I say, you can resolve all this by opening one single connection and transfer only 6kb of data, <strong>and</strong> every image will be transferred to the browser so your page will look like you&#8217;d have transferred all the images separately?</p>
<p>Follow please this link: <a href="http://sp.ask.com/i/h/sprite/b1.png" target="_blank">Ask.com&#8217;s sprites.</a><br />
What do you see? A bigger image which contains all the images which are used on Ask.com. In one single file they transferred all the images, thus minimizing server impact <strong>and</strong> minimizing the amount of transferred data. These are the sprites has been invented for. Cool, isn&#8217;t it?</p>
<p>So, how to use these sprites in our own life? It&#8217;s extremely simple: you dump all the images you want to use in one single image file, then you move that image as you want, using CSS.<br />
Using an example is easier to explain, so let&#8217;s see that example.</p>
<div style="float: left; padding:5px;"><img src="http://devoracles.com/images/sprite.png" alt="sprite example | Devoracles.com" /></div>
<p>The image file I will use is the one you see on the left. I will create a link and if you hover over it you will see another image as the link&#8217;s background, same applies if you click it.</p>
<style type="text/css">
.sprite a{
display:block;width:25px;height:25px;background:url(http://devoracles.com/images/sprite.png) no-repeat;
}
.sprite a:hover{
background-position: -27px 0;
}
.sprite a:active{
background-position:-54px 0;
}
</style>
<p>So, a live example:</p>
<div style="text-align:center; padding:5px;" class="sprite">
<a href="#" onclick="return false"></a>
</div>
<p>Try to click it, hover over it. You will notice a nice, smooth transition between the images, no waiting between the image loads.<br />
The style used which manages to make use of the sprite is this:</p>
<pre name="code" class="css">
.sprite a{
display:block;width:25px;height:25px;background:url(http://devoracles.com/images/sprite.png) no-repeat;
}
.sprite a:hover{
background-position: -27px 0;
}
.sprite a:active{
background-position:-54px 0;
}
</pre>
<p>How can sprites be in your favor? Well, they will speed up your website, <strong>considerably</strong> because of two factors: less time spent with opening/closing connections, then a single file will be <strong>much</strong> smaller than many small files. So you will save bandwidth.</p>
<p>Have questions? I&#8217;m here to answer them.</p>
]]></content:encoded>
			<wfw:commentRss>http://devoracles.com/css-taken-to-extreme-the-sprite/471/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
