解决方法
这是相当普遍的酒店列表图标显示设施。想象一下,列出50个酒店的页面,每个酒店有10个设施。 CSS Sprite是完美的这种事情 – 更好的用户体验,因为它的更快。但是如何为这些图像实现ALT标记。 Example site。
答案是他们不使用alt
文本,而是使用包含div的title
属性。
HTML
<div class="hotwire-fitness" title="Fitness Centre"></div>
CSS
.hotwire-fitness { float: left; margin-right: 5px; background: url(/prostyle/images/new_amenities.png) -71px 0; width: 21px; height: 21px; }
根据W3C(见上面的链接),title属性提供与alt属性相同的目的
Values of the title attribute may be rendered by user agents in a variety of ways. For instance,visual browsers frequently display the title as a “tool tip” (a short message that appears when the pointing device pauses over an object). Audio user agents may speak the title information in a similar context. For example,setting the attribute on a link allows user agents (visual and non-visual) to tell users about the nature of the linked resource:
alt
The alt attribute is defined in a set of tags (namely,img,area and optionally for input and applet) to allow you to provide a text equivalent for the object.
A text equivalent brings the following benefits to your web site and its visitors in the following common situations:
- nowadays,Web browsers are available in a very wide variety of platforms with very different capacities; some cannot display images at all or only a restricted set of type of images; some can be configured to not load images. If your code has the alt attribute set in its images,most of these browsers will display the description you gave instead of the images
- some of your visitors cannot see images,be they blind,color-blind,low-sighted; the alt attribute is of great help for those people that can rely on it to have a good idea of what’s on your page
- search engine bots belong to the two above categories: if you want your website to be indexed as well as it deserves,use the alt attribute to make sure that they won’t miss important sections of your pages.