Html “a 标签”中“img 标签”的工具提示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3658464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tooltip of an "img tag" inside an "a tag"
提问by Diego
I'd like to know the difference between title attr of the tag "a" and alt attr of the tag img.
我想知道标签“a”的title attr和标签img的alt attr之间的区别。
Also, wich should I use when I have an image inside an a? Just like in this case:
另外,当我在 a 中有图像时应该使用什么?就像在这种情况下:
<a class="duplicar" href="#"><img src="Images/btnSegDuplicar.gif" alt ="Duplicar" width="76" height="20" /></a>
Right now, as you can see, I'm using the alt but I'm having a little issue. No matter the browser in my development server the tooltips is shown, but in my production server it is not. I tried using both of them (alt and title) and it worked, but it is kind of uggly. Why is that difference between both servers?
现在,如您所见,我正在使用 alt,但遇到了一些小问题。无论我的开发服务器中的浏览器是否显示工具提示,但在我的生产服务器中却没有。我尝试同时使用它们(alt 和 title)并且它有效,但它有点难看。为什么这两个服务器之间存在差异?
回答by dxh
You should always use the title
attribute for tooltips. With images as well as with anchors.
您应该始终将该title
属性用于工具提示。使用图像以及锚点。
The alt
attribute is solely for the purpose of displaying a text when the image can not be viewed for some reason. That this text is sometimes shown as a tooltip is an incidental artifact of some implementations, and by no means a part of its specification.
该alt
属性仅用于在由于某种原因无法查看图像时显示文本。该文本有时显示为工具提示是某些实现的附带产物,绝不是其规范的一部分。