<?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>Learning the World &#187; background-image</title>
	<atom:link href="http://learningtheworld.eu/tag/background-image/feed/" rel="self" type="application/rss+xml" />
	<link>http://learningtheworld.eu</link>
	<description></description>
	<lastBuildDate>Tue, 06 Nov 2012 00:17:33 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
	<item>
		<title>Better Foreground Sprites</title>
		<link>http://learningtheworld.eu/2008/better-foreground-sprites/</link>
		<comments>http://learningtheworld.eu/2008/better-foreground-sprites/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 18:00:17 +0000</pubDate>
		<dc:creator><![CDATA[Martin Kliehm]]></dc:creator>
				<category><![CDATA[accessibility]]></category>
		<category><![CDATA[conferences]]></category>
		<category><![CDATA[downloads]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[background-image]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[css sprites]]></category>
		<category><![CDATA[foreground sprites]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[http-request]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[T.V. Raman]]></category>

		<guid isPermaLink="false">http://learningtheworld.eu/?p=106</guid>
		<description><![CDATA[A while ago I wrote about using <acronym title="Cascading Style Sheets">CSS</acronym> Sprites in <code>img</code> tags&#160;&#8212; <strong>Foreground Sprites</strong>. Thus you avoid HTTP requests, but the page turns really ugly when <acronym>CSS</acronym> is switched off because the sprite image will be displayed in its full size. Now Google&#8217;s accessibility specialist T.V. Raman explained their idea of using sprites for foreground images&#160;&#8212; a much better solution!]]></description>
				<content:encoded><![CDATA[<p>A while ago I wrote about using <a href="http://www.alistapart.com/articles/sprites/"><acronym title="Cascading Style Sheets">CSS</acronym> Sprites</a> in <code>img</code> tags, calling it <strong><a href="/2007/foreground-sprites/">Foreground Sprites</a></strong>. Thus you avoid performance-eating HTTP requests, but the page turns really ugly when <acronym>CSS</acronym> is switched off because the sprite image will be displayed in its full size. <img src="http://learningtheworld.eu/wp-includes/images/smilies/icon_sad.gif" alt=":(" class="wp-smiley" /> </p>

<p>What are the alternatives? Using background-images with off-screen text? Bad code:</p>

<ol class="code bad" title="HTML">
<li><code>&lt;a href=&quot;foo&quot; class=&quot;button&quot;&gt;</code></li>
<li class="indent"><code>&lt;span&gt;Alternative Text&lt;/span&gt;</code></li>
<li><code>&lt;/a&gt;</code></li>
</ol>

<ol class="code bad" title="CSS">
<li><code>a.button, button {</code></li>
<li class="indent"><code>background: url(foo.gif) 0 &minus;26px no-repeat;</code></li>
<li class="indent">display: block;</li>
<li class="indent">height: 52px;</li>
<li class="indent">overflow: hidden;</li>
<li class="indent">position: relative;</li>
<li class="indent">width: 150px;</li>
<li><code>}</code></li>
<li><code>span {</code></li>
<li class="indent"><code>left: &minus;9999px;</code></li>
<li class="indent"><code>position: absolute;</code></li>
<li class="indent"><code>top: auto;</code></li>
<li><code>}</code></li>
</ol>

<p><strong>That&rsquo;s a bad idea with accessibility issues.</strong> Screen readers will be able to read the text, but if somebody with low vision has high-contrast custom stylesheets, it is likely that the <code>background-image</code> won&rsquo;t be displayed. Still the alternative text will be invisible off-screen, so the link or <code>button</code> becomes unusable.</p>

<h3>A better solution</h3>

<p>Now Google&rsquo;s accessibility specialist <strong>T.V. Raman</strong> explained their idea for <a href="http://googlewebmastercentral.blogspot.com/2008/05/design-patterns-for-accessible.html">replacing  images with sprites</a>. Here are screenshots of Google search results with images, and with background images disabled:</p>

<p><img src="/wp-content/uploads/2008/06/screenshot-google-search-result-with-bgimage.png" width="400" height="84" alt="Screenshot displaying the Google logo" class="screenshot" />
<img src="/wp-content/uploads/2008/06/screenshot-google-search-result-wo-bgimage.png" width="400" height="84" alt="Screenshot with text visible instead of the logo" class="screenshot" /></p>

<p>Google puts the alternative text <strong><em>behind</em> the background image</strong> simply by attaching it on the <code>span</code> element, not the anchor. So when <acronym>CSS</acronym> or background images are turned off, the text just reappears.</p>

<ol class="code" title="XHTML">
<li><code>&lt;a id=&quot;logo&quot; title=&quot;Go to Google Home&quot; href=&quot;http://www.google.com/&quot;&gt;</code></li>
<li class="indent">Google</li>
<li class="indent"><code><strong>&lt;span&gt;<ins datetime="20080627T174700">&lt;/span&gt;</ins></strong></code></li>
<li><code>&lt;/a&gt;</code></li>
</ol>

<ol class="code" title="CSS">
<li><code>#logo {</code></li>
<li class="indent">display: block;</li>
<li class="indent">height: 52px;</li>
<li class="indent">overflow: hidden;</li>
<li class="indent">position: relative;</li>
<li class="indent">width: 150px;</li>
<li><code>}</code></li>
<li><code>#logo span {</code></li>
<li class="indent"><code>background: url(foo.gif) 0 &minus;26px no-repeat;</code></li>
<li class="indent"><code>height: 100%;</code></li>
<li class="indent"><code>left: 0;</code></li>
<li class="indent">position: absolute;</li>
<li class="indent">top: 0;</li>
<li class="indent"><code>width: 100%;</code></li>
<li><code>}</code></li>
</ol>

<p>There&rsquo;s only an issue if you have <em>a lot</em> of alternative text, perhaps combined with text zoom, so that it doesn&rsquo;t fit in the reserved space. But I can live with that.</p>

<p>Congratulations to Google for this ellegant solution, and it&rsquo;s <em>so</em> simple! Why didn&rsquo;t <em>I</em> think of it? <img src="http://learningtheworld.eu/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /> </p>
]]></content:encoded>
			<wfw:commentRss>http://learningtheworld.eu/2008/better-foreground-sprites/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
