简体   繁体   English

HTML 标题属性优先级

[英]HTML title attribute precedence

Can i assume that a title attribute in <img> always takes precedence over a title attribute in <a>?我可以假设 <img> 中的标题属性总是优先于 <a> 中的标题属性吗? (html5 spec/standard) (html5 规范/标准)

EX:前任:

<a title="foo">
  <img title="bar">
</a>

tooltip: bar

EX2: EX2:

<a title="foo">
  <img title="bar" id="1">
  <img id="2">
</a>

tooltip#1: bar
tooltip#2: foo

According to the WHATWG (HTML standards working group):根据WHATWG (HTML 标准工作组):

If this attribute is omitted from an element, then it implies that the title attribute of the nearest ancestor HTML element with a title attribute set is also relevant to this element.如果从元素中省略此属性,则意味着具有标题属性集的最近祖先 HTML 元素的标题属性也与此元素相关。 Setting the attribute overrides this, explicitly stating that the advisory information of any ancestors is not relevant to this element.设置属性会覆盖此属性,明确指出任何祖先的咨询信息与此元素无关。 Setting the attribute to the empty string indicates that the element has no advisory information.将该属性设置为空字符串表示该元素没有建议信息。

So this tells us that it's not about a or img , it's about where it's at in the child/ancestor relationship.所以这告诉我们,这不是关于aimg ,而是关于它在子/祖先关系中的位置。 The child will always take precedence.孩子永远是优先的。

However, Title attribute is also discouraged.但是,也不鼓励使用 Title 属性。 (See the note on the page I linked). (请参阅我链接的页面上的注释)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM