元素 h1 不得显示为地址元素的后代



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

我正在使用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,因为作者的名字也是网站的名称。

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

嗯。

雷纳托·罗德里格斯:"我理解这个错误。我使用的是h1,因为作者的名字也是网站的名称。

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

该标题是您正文的标题

还是正文中某个部分的标题?如果它是一个部分的标题,那么你需要把它从那里拿出来,把它直接放在正文上:示例:http://w3-video.com/Web_Technologies/HTML5/html5_address_tag.php

解决了。

即使标题与作者姓名相同,它们对应的东西也不同。上移标题,并在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>

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

最新更新