2

我想使用语义标记来强调每个项目的重要性或优先级。

这是我的意思的一个例子。

<ul itemscope itemtype="http://schema.org/ItemList">
  <h2 itemprop="name">Wish List</h2><br>
  <li itemprop="itemListElement">Google glass</li>
  <li itemprop="itemListElement">Galaxy S4</li>
  <li itemprop="itemListElement">MacBook Pro</li>
</ul>

我正在考虑使用标题标签,但我不确定这是否正确使用。例如

<ul itemscope itemtype="http://schema.org/ItemList">
  <li itemprop="itemListElement"><h6>Least Important</h6></li>
  <li itemprop="itemListElement"><h1>Most Important</h1></li>
</ul>

我只是在寻找一些关于是否有正确的方法的建议?可能是微数据、微格式或 RDFa?

4

2 回答 2

2

你不应该那样使用标题。标题内容很重要,是的,但这并不意味着重要的内容应该是标题。您的第一个示例无效(列表可能仅包含li元素),您的第二个示例与文档大纲混淆。

strong元素代表“对其内容的强烈重要性”。strong您可以通过对相同内容使用多个元素来增加重要性:

一段内容的相对重要性由其祖先strong元素的数量给出;每个strong元素都会增加其内容的重要性。

HTML5 规范也有一个这样的用法示例:

<p>
  <strong>Warning.</strong> This dungeon is dangerous.
  <strong>Avoid the ducks.</strong> Take any gold you find.
  <strong><strong>Do not take any of the diamonds</strong>,
  they are explosive and <strong>will destroy anything within
  ten meters.</strong></strong> You have been warned.
</p>

(注意<strong>Do not take any of the diamonds</strong>嵌套在另一个strong元素中)

所以这是HTML5中的正确方法。

关于您的示例:如果您有一个从最不重要到最重要(或相反)排序的愿望清单,您应该使用ol而不是ul,因为顺序是有意义且重要的。因此,您的愿望清单可能如下所示:

<ol reversed>
  <li><!-- least important item --></li> 
  <li><!-- another not-soo-very important one --></li>
  <li><strong><!-- important --></strong></li>
  <li><strong><!-- more important than the previous one, but not that much of a difference --></strong></li>
  <li><strong><strong><!-- most important item --></strong></strong></li> 
</ol>

(如果没有以这种方式排序,请相应地使用ul并使用strong元素。)


现在,您当然可以使用 RDFa 或 Microdata 来增强它。因此,您需要一个适当的词汇表。我一个都不知道。也许您可以使用某种评分词汇?你可以给每个项目打分/评分,比如你想要多少。

Turtle 中的理论示例:

myWishlistItems:1 ex:hasImportance 0.9
myWishlistItems:2 ex:hasImportance 0.85
myWishlistItems:3 ex:hasImportance 0.7
myWishlistItems:4 ex:hasImportance 0.7
myWishlistItems:5 ex:hasImportance 0.7
myWishlistItems:6 ex:hasImportance 0.2

备选方案:说明内容中的语义,例如对重要性级别进行分组。

您可以使用dl,例如:

<section>
  <h1>My wishlist</h1>

  <dl>
    <dt>MUST HAVE!</dt>
      <dd>…&lt;/dd>
      <dd>…&lt;/dd>
    <dt>Would be very cool</dt>
      <dd>…&lt;/dd>
      <dd>…&lt;/dd>
    <dt>I like that, sometimes</dt>
      <dd>…&lt;/dd>
      <dd>…&lt;/dd>
  </dl>

</section>

ol带有section元素,因此您可以使用分组标题,例如:

<section>
  <h1>My wishlist</h1>

  <ol>

    <li>
      <section>
        <h2>MUST HAVE!</h2>
        <ul>
          <li>…&lt;/li>
          <li>…&lt;/li>
        </ul>
      </section>
    </li>

    <li>
      <section>
        <h2>Would be very cool</h2>
        <ul>
          <li>…&lt;/li>
          <li>…&lt;/li>
        </ul>
      </section>
    </li>

    <li>
      <section>
        <h2>I like that, sometimes</h2>
        <ul>
          <li>…&lt;/li>
          <li>…&lt;/li>
        </ul>
      </section>
    </li>

  </ol>

</section>
于 2013-05-11T21:05:45.317 回答
1

如果您想要具有多个优先级的比例,则无法在 html 中执行此操作。使用标题会使大纲混乱,以一种明显“非语义”的方式。也可能不值得尝试用 RDF 来表达。什么会消耗它?也许你有更多的细节,这会更清楚地说明这一点......

由于无法在 HTML 元素或属性中表达它,因此所有读者都无法访问数据。您知道如何使用一系列颜色为项目设置样式,但屏幕阅读器不会大声朗读这些颜色。

您可以将其简化为有序列表 - 按优先顺序排列的项目。或两个重要性级别,其中一些关键项目使用<strong>.

(如果您从字面上理解 HTML5 规范,您可以嵌套<strong>多次以获得更高级别的优先级。但您的用例不太可能支持它。不在当前的屏幕阅读器中,也不在浏览器默认样式表中。所以我不会t 认为这是合法的使用)。

于 2013-05-11T20:02:19.630 回答