【问题标题】:The element h1 must not appear as a descendant of the address element元素 h1 不得作为地址元素的后代出现
【发布时间】:2014-01-08 21:58:41
【问题描述】:

我正在开发一个个人网站,第一部分必须包含作者详细信息(例如他工作的组织和电子邮件)。我正在尝试为搜索引擎爬虫设置内容。

我正在使用 HTML 5 和微数据。下面是代码:

<header>
  <address itemscope itemtype="http://schema.org/Person">
    <h1 lang="pt" itemprop="name">Lorem Ipsum Dolor Sit Amet</h1>
    <img itemprop="image" src="http://lorempixel.com/150/200/" lang="pt" alt="Lorem Ipsum Dolor Sit Amet">
    <p itemprop="jobTitle">Professor of ...</p>
    <div itemprop="worksFor" itemscope itemtype="http://schema.org/Organization">
      <span itemprop="department" itemscope itemtype="http://schema.org/Organization"><span lang="pt" itemprop="name">Departamento de ...</span></span><br>
      <span itemprop="name" lang="pt">Faculdade de Engenharia ...</span><br>
      <div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
        <span itemprop="streetAddress">Rua Dr. Roberto ...</span>, <span itemprop="postalCode">4200-465</span> <span itemprop="addressLocality">Porto, Portugal</span>
      </div>
    </div>
    <p>Email: <a itemprop="email" href="mailto:foo@bar.com">foo@bar.com</a></p>
  </address>
</header>

使用 W3C 验证器,我收到错误:

Line 11, Column 38: The element h1 must not appear as a descendant of the address element.

<h1 lang="pt" itemprop="name">Lorem Ipsum Dolor Sit Amet</h1>

我理解错误。我用的是h1,因为作者的名字也是网站的名字。

我的问题是你将如何解决这个问题?

【问题讨论】:

  • ....将它移到
    上方?
  • @Diodeus 会破坏语义。
  • @Diodeus 它与 schema.org 的东西没有任何关系; HTML 规范说明了哪些元素可以出现在其他元素中。
  • 请注意,HTML5(仍在不断变化)提到 the address element 表示“地址元素表示其最近的文章或正文元素祖先的联系信息。如果那是正文元素,那么联系信息适用于整个文件。”标题出现在这样的元素中是没有意义的。
  • 很多东西出现在多个地方,但这并不意味着它们是同一个东西。我不会将信件发送到文件的标题,而是将其发送到通信地址。它们是不同的东西,即使它们碰巧共享一些文本。如果其他人成为文档的维护者,那么他们的名字应该列在地址中,即使文档的标题保持不变。标题和联系人在语义上是不同的东西。如果您不想显示其中之一,那就是 CSS 的问题。

标签: html seo semantic-web semantic-markup microdata


【解决方案1】:

嗯..

Renato Rodrigues:“我理解错误。我使用的是 h1,因为作者的名字也是网站的名称。”

如果作者的名字也是网站的名字,那么作者的地址就是文档的地址,就是你的html页面的地址,对吧?

该标题是您的正文的标题还是正文中某个部分的标题? 如果它是一个部分的标题,那么您需要将它从那里取出并将其直接放在正文上: 例如:http://w3-video.com/Web_Technologies/HTML5/html5_address_tag.php

【讨论】:

  • 是正文的头部。
  • "如果地址嵌套在footerfooter 嵌套在body 中,地址元素允许您标记整个网页的联系信息" 如果父容器是header 而不是 footer
【解决方案2】:

解决了。

即使标题和作者的名字一样,它们对应的东西也不同。将标题上移并在address 中添加了带有人名的meta 标签。

<body>
  <header>
    <h1 lang="pt">Lorem Ipsum Dolor Sit Amet</h1>
    <address itemscope itemtype="http://schema.org/Person">
      <meta lang="pt" itemprop="name" content="Lorem Ipsum Dolor Sit Amet">
      <img itemprop="image" src="http://lorempixel.com/150/200/" lang="pt" alt="Lorem Ipsum Dolor Sit Amet">
      <p itemprop="jobTitle">Professor of ...</p>
      <div itemprop="worksFor" itemscope itemtype="http://schema.org/Organization">
        <span itemprop="department" itemscope itemtype="http://schema.org/Organization"><span lang="pt" itemprop="name">Departamento de ...</span></span><br>
        <span itemprop="name" lang="pt">Faculdade de Engenharia ...</span><br>
        <div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
          <span itemprop="streetAddress">Rua Dr. Roberto ...</span>, <span itemprop="postalCode">4200-465</span> <span itemprop="addressLocality">Porto, Portugal</span>
        </div>
      </div>
      <p>Email: <a itemprop="email" href="mailto:foo@bar.com">foo@bar.com</a></p>
    </address>
  </header>
  ...
</body>

【讨论】:

    【解决方案3】:

    是的,如果它是正文的标题,那么没关系:标题内的地址,正文上的标题

    【讨论】:

      猜你喜欢
      • 2014-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多