<?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>Web 3.0, 6 Bladed Razors, 7 Minute Abs &#187; css-sprites</title>
	<atom:link href="http://www.zachleat.com/web/tag/css-sprites/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zachleat.com/web</link>
	<description></description>
	<lastBuildDate>Fri, 30 Jul 2010 01:59:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>DIY Webdings &#8211; CSS Sprites using @font-face</title>
		<link>http://www.zachleat.com/web/2010/01/03/css-sprites-using-font-face/</link>
		<comments>http://www.zachleat.com/web/2010/01/03/css-sprites-using-font-face/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 00:48:29 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[css-sprites]]></category>
		<category><![CDATA[font-face]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/?p=433</guid>
		<description><![CDATA[Almost everyone knows the Webdings font or its sibling Wingdings. Even if you don&#8217;t, chances are pretty good that it&#8217;s installed on your system. Webdings is a symbol font designed in 1997 as a response to the need of Web designers for a fast and easy method of incorporating graphics in their pages. &#8230; Webdings [...]]]></description>
			<content:encoded><![CDATA[<p>Almost everyone knows the Webdings font or its sibling Wingdings.  Even if you don&#8217;t, chances are pretty good that it&#8217;s installed on your system.</p>
<blockquote><p>Webdings is a symbol font designed in 1997 as a response to the need of Web designers for a fast and easy method of incorporating graphics in their pages.<br />
&#8230;</p>
<p>Webdings is ideal for enriching the appearance of a Web page. Because it’s a font, it can be installed on the user’s system, (or embedded in the document itself) is fully scaleable [sic] and quick to render. It’s a perfect way of including graphics on your site without making users wait for lots of graphic files to download.</p>
<p> &#8211; Source <a href="http://www.microsoft.com/typography/fonts/family.aspx?FID=5">Microsoft Typography</a></p></blockquote>
<p>Microsoft was onto something here, and there is a nice parallel that can be drawn between the font and a CSS sprite: namely that multiple images are stored under the guise of a single HTTP request.  So, why not create our own font and use it as a CSS sprite?  Each character in the font (glyph) will be a single image in the sprite.</p>
<h2>Why is this awesome?</h2>
<ul>
<li>We can <strong>change the color</strong> of our font using nothing but CSS <code>color</code>.  This is a big one.  We don&#8217;t have to have separate images for hover states!  And if we want to change the color scheme, there are no new images to generate and we don&#8217;t have to make any changes to the font to do so.</li>
<li>Don&#8217;t have to monkey around with difficult to maintain CSS positioning code.</li>
<li>Fonts scale, graphics don&#8217;t.  Zooming in on a graphic will result in a pixelated image, but fonts will be smooth like a 6 blade razor shave.  Try zooming on the demo file below.</li>
</ul>
<h2>Why is this not awesome?</h2>
<ul>
<li>Font glyphs can only contain one color.</li>
<li>May experience the Flash of unstyled text (FOUT) while the font is loading.</li>
<li>Extra markup required for IE6 and IE7.  While @font-face is supported in all non-extinct versions of IE, each @font-face sprite requires a corresponding text character on the screen.  For instance, <code>&lt;span style="font-family: MyCustomFont;"&gt;A&lt;/span&gt;</code>, the A is required to display the @font-face Sprite stored under the A glyph.<br/><br />
Luckily, in most browsers we can inject a character using CSS :after/:before and the <code>content</code> property.  Unfortunately, this is <a href="http://www.quirksmode.org/css/beforeafter_content.html">not supported in IE6 or IE7</a>.  I haven&#8217;t investigated whether or not this might be solved using other means (CSS expressions) yet.</li>
<li>Safari asks for permission to use the font with a scary popup box, which I assume is a security precaution gleaned from the Windows Vista playbook.</li>
</ul>
<h2>Demo</h2>
<p>The following <a href="http://jquery-ui.googlecode.com/svn/trunk/tests/static/icons.html">jQuery UI Icons</a> are currently used in jQuery UI and are stored in <a href="http://jqueryui.com/themeroller/images/?new=888888&#038;w=256&#038;h=240&#038;f=png&#038;fltr[]=rcd|256&#038;fltr[]=mask|icons/icons.png">one big CSS sprite</a>.</p>
<p>It was pretty trivial to create <a href="http://fontstruct.fontshop.com/fontstructions/show/jquery_ui_icons_1">a font</a> with a subset of the jQuery UI icons (only the first 20, just a proof of concept here) using the wonderful <a href="http://fontstruct.fontshop.com/">FontStruct</a> utility.  Then, I took the TTF generated by FontStruct and plugged it into the completely lovely <a href="http://www.fontsquirrel.com/fontface/generator">FontSquirrel @font-face Kit Generator</a>.  That gave me everything I needed for a fully cross-browser test.</p>
<ul>
<li><a href="http://www.zachleat.com/test/fonts/font.html" style="font-size: 160%; font-weight: bold;">View the Demo</a></li>
</ul>
<p>Let me know what you think!</p>
<div style="font-size: 80%">
Successfully tested on:</p>
<ul>
<li>Google Chrome 4 (Mac)</li>
<li>Safari 4 (Mac)</li>
<li>Firefox 3.5 (Mac and Windows)</li>
<li>Internet Explorer 8</li>
<li>With documented limitations above:
<ul>
<li>Internet Explorer 6</li>
<li>Internet Explorer 7 (Compatibility Mode in IE8)</li>
</ul>
</li>
</ul>
<p>Does not work on (no @font-face support):</p>
<ul>
<li>Google Chrome 3 and prior</li>
<li>Firefox 3 and prior</li>
</ul>
</div>
<p>Read more about <a href="http://paulirish.com/2009/bulletproof-font-face-implementation-syntax/">@font-face support from Paul Irish</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/2010/01/03/css-sprites-using-font-face/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
	</channel>
</rss>
