对于一个锚链接,使用alt标签是正确的吗?例如:
<a href="#" class="test" alt="Something" src="sfasfs" ></a>
a
element":https://www.w3.org/TR/html5/text-level-semantics.html#the-a-element
3. 检查 "Content attributes",其中列出了a
元素允许使用的所有属性:
4. 检查链接的 "Global attributes":https://www.w3.org/TR/html5/dom.html#global-attributes 你会发现,
- 全局属性
href
target
download
rel
hreflang
type
a
元素不允许使用alt
属性。src
属性也不允许使用。
通过验证你的HTML,这样的错误将被报告给你。
a
元素可以有另一个属性:rev
。对于锚点,应该使用title。alt 不是 a
标签的有效属性。参见http://w3schools.com/tags/tag_a.asp
“title” 在浏览器中得到了广泛应用。尝试:
"<a href="#" title="hello">asf</a>
title
是不正确的(尽管大多数浏览器都会实现它)。 - felwithehttp://www.w3.org/MarkUp/1995-archive/Elements/A.html
或者,更有益的是,您可以使用ARIA可访问性属性aria-label
(不要与aria-labeledby
混淆)。 aria-label
对于非图像元素具有与alt属性对于图像相同的功能,并包括一些优化措施,因为您正在为屏幕阅读器进行优化。
http://www.w3.org/WAI/GL/wiki/Using_aria-label_to_provide_labels_for_objects
我使用了标题,它起到了作用!
标题属性提供链接的标题。除一种情况外,它完全是建议性的。该值为文本。例外情况是针对样式表链接,其中标题属性定义了备用样式表集。
<a class="navbar-brand" href="http://www.alberghierocastelnuovocilento.gov.it/sito/index.php" title="sito dell'Istituto Ancel Keys">A.K.</a>
a
元素都不允许使用alt
属性(它应该是一个属性,而不是标签)。此外,似乎也没有任何浏览器将其识别为具有任何意义的属性。alt
属性来与img
元素的alt
属性类比,期望在鼠标悬停时看到一个“工具提示”。但这样做存在两个问题。首先,每个元素都有自己的属性,在每个元素的规范中定义。其次,某些古老浏览器中alt
属性呈现为“工具提示”的方式可能只是一种怪癖甚至是错误,而非可以预期的东西;alt
属性应该只在因某种原因未显示图像时向用户呈现。title
属性,或者更好的方法是搜索“CSS工具提示”并使用您喜欢的基于CSS的工具提示(它们可以被描述为隐藏的“层”,在鼠标悬停时变为可见)。我很惊讶地看到所有的答案都声称在a
标签中使用alt
属性是无效的。这是绝对错误的。
Html不会阻止您使用任何属性:
<a your-custom-attribute="value">Any attribute can be used</a>
a
中使用 alt
属性是语义上正确的,那么我的回答是:<img alt="image description" />
。a::after {
content: attr(color); /* attr can be used as content */
display: block;
color: white;
background-color: blue;
background-color: attr(color); /* This won't work */
display: none;
}
a:hover::after {
display: block;
}
[hidden] {
display: none;
}
<a href="#" color="red">Hover me!</a>
<a href="#" color="red" hidden>In some cases, it can be used to hide it!</a>
再次强调,如果你问是否语义上正确使用自定义属性,我会说:
不是。使用 data-*
属性来实现语义化。
哎呀,这个问题是在2013年提出的。
a
全局属性中看到title
属性,是否可以在a
中使用这样的title
属性? - Yousef Altaftitle
。 - unor