微数据标记周围的h1,h2,h3

时间:2016-10-24 10:01:05

标签: html schema.org microdata html-heading

我正在尝试将微数据标记(使用Schema.org)添加到页面中。目前,代码如下所示:

<div itemscope itemtype="http://schema.org/Product">
    <div class="primary">
        <div itemprop="brand" itemscope itemtype="http://schema.org/Brand">
            <span itemprop="name">Acme Co</span>
        </div>
        <h4 itemprop="name">Blue Widget</h4>
    </div>
</div>

但是,我想要做的是将h4从“Blue Widget”更改为“Acme Co Blue Widget”。我已经有Brand类型封装的公司名称,所以我不想在页面上重复它。这就是我在想的。

可能的解决方案

<div itemscope itemtype="http://schema.org/Product">
    <h4 class="primary">
        <span itemprop="brand" itemscope itemtype="http://schema.org/Brand">
            <span itemprop="name">Acme Co</span>
        </span>
        <span itemprop="name">Blue Widget</span>
    </h4>
</div> 

这不是Microdata / Schema.org标记是否有效(我可以测试)的问题,但是浏览器会根据我的需要读取标题 - “Acme Co Blue Widget”?我对Schema.org的所有内容都不确定。

1 个答案:

答案 0 :(得分:1)

是的,没关系。

heading elements h1-h6可以包含phrasing content(包括span)。由于span元素毫无意义,因此这些h4在语义上是等价的:

<h4>Foobar</h4>
<h4><span>Fo<span>o</span>bar</span></h4>

Microdata属性不会更改HTML语义。

您的解决方案的替代方案是使用meta元素(但如果您对解决方案感到满意,则无需使用此替代方案):

<div itemscope itemtype="http://schema.org/Product">
  <span itemprop="brand" itemscope itemtype="http://schema.org/Brand">
    <meta itemprop="name" content="Acme Co" />
  </span>
  <h4 itemprop="name" class="primary">Acme Co Blue Widget</h4>
</div>
相关问题