将alt标签用于锚链接是否正确? [英] Is it correct to use alt tag for an anchor link?

查看:112
本文介绍了将alt标签用于锚链接是否正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将alt标签用于锚链接是正确的,例如

 < a href =#class =testalt =Somethingsrc =sfasfs>< / a> 


解决方案

通过查看官方规范:


  1. 查看规格: https://www.w3.org/TR/html5/


  2. 搜索 a element: https://www.w3。 org / TR / html5 / text-level-semantics.html#元素


  3. 勾选内容属性,列出所有允许 a 元素的属性:



    • 全局属性

    • href

    • 目标

    • 下载

    • rel

    • hreflang

    • 类型



  4. 检查链接的全局属性: https://www.w3.org/TR/html5/dom.html#global-attributes


  5. ol>

    正如您将看到的, alt 属性不允许位于 a 元素。

    您也会注意到 src 属性也是不允许的。



    通过验证您的HTML ,会向您报告类似的错误。






    请注意,以上是 HTML5 ,它是 W3C的HTML标准从2014年开始。 2016年, HTML 5.1 成为下一个HTML标准。查找允许的属性以相同的方式工作。您会发现 a 元素在HTML 5.1中可以有另一个属性: rev



    您可以在 W3C的 HTML电流中找到所有HTML规范(包括最新标准)状态


    Is it correct to use alt tag for an anchor link, something like

    <a href="#" class="test" alt="Something" src="sfasfs" ></a>
    

    解决方案

    Such things are best answered by looking at the official specification:

    1. go to the specification: https://www.w3.org/TR/html5/

    2. search for "a element": https://www.w3.org/TR/html5/text-level-semantics.html#the-a-element

    3. check "Content attributes", which lists all allowed attributes for the a element:

      • Global attributes
      • href
      • target
      • download
      • rel
      • hreflang
      • type

    4. check the linked "Global attributes": https://www.w3.org/TR/html5/dom.html#global-attributes

    As you will see, the alt attribute is not allowed on the a element.
    Also you’d notice that the src attribute isn’t allowed either.

    By validating your HTML, errors like these are reported to you.


    Note that the above is for HTML5, which is W3C’s HTML standard from 2014. In 2016, HTML 5.1 became the next HTML standard. Finding the allowed attributes works in the same way. You’ll see that the a element can have another attribute in HTML 5.1: rev.

    You can find all HTML specifications (including the latest standard) on W3C’s HTML Current Status.

    这篇关于将alt标签用于锚链接是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆