看这个 例子,区别在于后者使用了带 alt=”error” 的 img 标签,而前者完全是背景。
前者代码:
Your postal/zip code was not in the correct format.
div.error {
background: #ffcccc url(../images/error_small.png) no-repeat 5px 4px;
…
}
后者代码:

Your postal/zip code was not in the correct format.
div.bettererror {
background-color: #ffcccc;
…
}
前者的好处是无论是正确、错误、警告或者其它什么提示信息页面,html代码部分几乎都是一模一样的,只要修改 div 的 class 即可。后者的好处是这样更 accessibility,不显示背景或者文本的浏览器也可以得到正确的信息。
下图是我用 opera 模拟文本浏览器的效果示意。你可以看到,下面那个 img 的 alt 会显示在内容中。

Leave a reply