<?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>Mozilla Web Development &#187; Design</title>
	<atom:link href="http://blog.mozilla.com/webdev/category/design/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mozilla.com/webdev</link>
	<description>Everybody Likes Ninjas</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:50:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CSS Spriting Tips</title>
		<link>http://blog.mozilla.com/webdev/2009/03/27/css-spriting-tips/</link>
		<comments>http://blog.mozilla.com/webdev/2009/03/27/css-spriting-tips/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 22:36:32 +0000</pubDate>
		<dc:creator>rdoherty</dc:creator>
				<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/webdev/?p=325</guid>
		<description><![CDATA[One of the most effective ways of speeding up a website&#8217;s render time is to reduce the number of HTTP requests required to fetch content. An effective method to achieve this is via CSS sprites, which is combining multiple images into one large image and using CSS to only display parts of it.
Here&#8217;s an example [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most effective ways of speeding up a website&#8217;s render time is to reduce the number of HTTP requests required to fetch content. An effective method to achieve this is via CSS sprites, which is combining multiple images into one large image and using CSS to only display parts of it.</p>
<p>Here&#8217;s an example sprite:</p>
<p><a href="http://blog.mozilla.com/webdev/files/2009/03/main-sprites1.png"><img src="http://blog.mozilla.com/webdev/files/2009/03/main-sprites1.png" alt="Sprite Example" title="Sprite Example" width="450" height="548" class="alignnone size-full wp-image-335" /></a></p>
<p>The purpose of this post is not to show how it makes a site faster, but cover some best practices when creating a CSS sprite.</p>
<h3>Don&#8217;t wait until you are done slicing to begin spriting. </h3>
<p>The problem with waiting until you&#8217;ve built the site is all your CSS and images have already been created. You will have to go back and re-write your CSS. You&#8217;ll also spend a ton of time in Photoshop attempting to fit 20-30 graphics into a sprite at once, which is extremely painful and tedious. It&#8217;s much easier to build the sprite step by step.</p>
<h3>Arrange images opposite of how they will be displayed</h3>
<p>This tip is a little confusing and I didn&#8217;t learn this until I was halfway through creating a large sprite. If an image is supposed to appear on the left of an element: </p>
<p><a href="http://blog.mozilla.com/webdev/files/2009/03/picture-2.png"><img src="http://blog.mozilla.com/webdev/files/2009/03/picture-2.png" alt="Sprite positioning example" title="Sprite positioning example" width="203" height="28" class="alignnone size-full wp-image-338" /></a></p>
<p>Put that image to the right of the sprite (see sprite image from above). This way when you move the background image via CSS, there is no possible way any other image will display next to it. A common problem when creating CSS sprites is positioning images so they don&#8217;t appear as part of a background for the wrong element.</p>
<h3>Avoid &#8216;bottom&#8217; or &#8216;right&#8217; in CSS when positioning</h3>
<p>When positioning a CSS sprite behind an element, it&#8217;s very easy to use background-position: bottom -300px; or background-position: right -200px;. This will work initially, but the problem with it is once you expand your sprite in width or height, your positioning will be wrong as the images are no longer at the bottom or right of the sprite. Using explicit positioning in pixels avoids this issue.</p>
<h3>Give each image plenty of space</h3>
<p>As you can see from the example sprite, many tiny images are given lots of space. Why not just cram them all together to make the sprite smaller? Because the elements they are used on will most likely have variable content and need that extra padding so other images don&#8217;t show up.</p>
<p>Here&#8217;s an example:<br />
<a href="http://blog.mozilla.com/webdev/files/2009/03/picture-3.png"><img src="http://blog.mozilla.com/webdev/files/2009/03/picture-3.png" alt="Variable content example" title="Variable content example" width="302" height="189" class="alignnone size-full wp-image-342" /></a></p>
<p>Each list item has a graphical number as a background image. If you look at the sprite shown above, you can see how the images were staggered so that if the content increased, no other images would show up. </p>
<h3>Don&#8217;t worry about sprite pixel size</h3>
<p>Chances are if your site is decently designed, you will have a lot of images to put in your sprite. And you&#8217;ll need a pretty large sprite to space the images out appropriately. And that&#8217;s <strong>fine</strong>. Empty space in a sprite does not take up much of a file&#8217;s size.  The <a href="https://addons.mozilla.org/img/sprite.png?20081210">sprite used for addons.mozilla.org</a> is 1,000&#215;2,000 pixels and is only <strong>16.7kb!</strong></p>
<p>Got other tips? Leave a comment!</p>
<h3>More Resources</h3>
<ul>
<li><a href="http://css-tricks.com/css-sprites-what-they-are-why-theyre-cool-and-how-to-use-them/">CSS Sprites Tutorial</a></li>
<li><a href="http://spritegen.website-performance.org/">CSS Sprite Generator</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/webdev/2009/03/27/css-spriting-tips/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
	</channel>
</rss>
