CSS sprites最大限度地访问?(CSS sprites for maximum accessibility?)

假设我想用一个奇特的图像箭头替换一个链接> 。 为此,我想使用CSS精灵。

在许多文章中,例如在Smashing Magazine 最近的一篇(2012年)文章中,推荐的方法是这样的:


<a href="/article/123" class="nextLink">&gt;</a>



有趣的是,我发现Paciello集团的一篇 文章 (2010年)提出了一个看起来很好的解决方案。 我们的想法是在要替换的文本旁边放置一个<span> 。 <span>具有背景图像,位于文本顶部。 如果图像加载,它将替换文本,否则文本仍然可见。

为什么这种方法没有被广泛使用? 这个解决方案有问题吗?

Suppose I want to replace a link > with a fancy image arrow. For that I want to use a CSS sprite.

In many articles, for example in a recent (2012) article in Smashing Magazine, the recommended method is something like this:


<a href="/article/123" class="nextLink">&gt;</a>

CSS: hide text and specify sprite as background

However this method is problematic concerning accessibility: If images are disabled but CSS is interpreted, then the above link will be invisible.

Interestingly, I found an old (2010) article by Paciello Group that proposes what looks like a good solution. The idea is to place a <span> next to the text to be replaced. The <span> has a background image and is positioned on top of the text. If the image loads, it replaces the text, otherwise the text is still visible.

Why is this method not widely employed? Are there issues with that solution?


主要的缺点是在加载CSS精灵之前向没有特殊辅助功能需求的用户显示文本。 在代码方面,它也可能不像使用aria-label解决方案那样语义清晰(如下所述)。


aria-label属性用于定义标记当前元素的字符串。 在屏幕上看不到文本标签的情况下使用它。



在Gmail中,“上一个”按钮的咏叹调标签为“较旧” 在Facebook中,右上方的“cog”图标有一些文本“帐户设置”缩进-5000em

The main disadvantage is showing the text to users with no special accessibility needs, before your CSS sprite loads. In terms of code, it is also perhaps not as semantically clean as using an aria-label solution (explained below).

You could consider using an ARIA label for the element:

The aria-label attribute is used to define a string that labels the current element. Use it in cases where a text label is not visible on the screen.


I quickly checked how Gmail and Facebook approach this problem (buttons without text):

In Gmail the 'previous' button has an aria-label of 'Older' in Facebook the 'cog' icon in top right has some text 'Account Settings' indented -5000em