gpt4 book ai didi

html - 我可以在 标签中嵌套一个
元素吗?

转载 作者:行者123 更新时间:2023-12-04 12:26:23 25 4
gpt4 key购买 nike

根据 HTML5 文档,链接标签 <a>接受所有内容,但是,这真的正确吗?

对于图形元素,哪一个是有效的?如果不止一个是有效的,那么在任何客观方面,它们中的任何一个都比另一个更好吗?

  • <figure class="box">
    <a href="#">
    <img src="" alt="" />
    <figcaption>Hello!</figcaption>
    </a>
    </figure>
  • <a href="#" class="box">
    <figure>
    <img src="" alt="" />
    <figcaption>Hello!</figcaption>
    </figure>
    </a>
  • <figure class="box">
    <a href="#">
    <img src="" alt="" />
    </a>
    <figcaption>Hello!</figcaption>
    </figure>
  • 最佳答案

    片段#1 是无效的(从某种意义上说,它没有通过一致性检查器(例如 Validator.nu)的验证),因为 a figcaption may not appear as a child of any element but a figure .

    片段 #2 和 #3 符合 HTML5,但它们的含义不同。开始,here是规范所说的 a元素:

    If the a element has an href attribute, then it represents a hyperlink (a hypertext anchor) labeled by its contents.



    考虑到这一点:

    #2中,图中为超链接内容。

    在#3 中,只有图像是超链接内容。标题不是超链接的一部分。然而,图像和标题都是图形的一部分。

    因为它们的含义不同,所以从一般意义上讲,它们都不比另一个“更好”。你想让整个图形成为一个超链接吗?然后使用#2。您是否只想将图像作为超链接?然后使用#3。

    关于html - 我可以在 <a> 标签中嵌套一个 <figure> 元素吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31387153/

    25 4 0