html - w3c 验证警告 : Article lacks heading

标签 html w3c-validation

我的页面只包含以下 HTML 代码:

<article>
    <nav>
        <a href="test.html" rel="parent">Back</a>
    </nav>
    <header>
        <h2>Test</h2>
    </header>
    <p>Test</p>
</article>

当我尝试 validate it 时为什么会收到此警告?

Warning: Article lacks heading. Consider using h2-h6 elements to add identifying headings to all articles.

From line 10, column 2; to line 10, column 10

<body>↩↩↩<article>↩ <na

最佳答案

原因是分段内容元素(在您的情况下为 nav)位于标题内容元素(在您的情况下为 h2)之前:

<!-- A -->
<article>
  <nav></nav>
  <h2>Test</h2>
</article>

如果你切换它们,验证器不会报告警告:

<!-- B -->
<article>
  <h2>Test</h2>
  <nav></nav>
</article>

查看这些片段生成的文档概述部分:

<!-- A -->

- article (no heading)
-- nav (no heading)
- "Test" (h2 of an implied section, on the same level as the article)
<!-- B -->

- "Test" (h2 of article)
-- nav (no heading)

规范引用

Creating an outline描述算法。我认为相关的步骤是这一步(但我不习惯阅读此类算法,所以最好持保留态度):

When entering a sectioning content element
Run these steps:

  1. If current outline owner is not null, run these substeps:

    1. If the current section has no heading, create an implied heading and let that be the heading for the current section.

据我了解,这就是示例“A”所发生的情况:

  1. 算法输入一个分段内容元素(article)。
  2. 它找到一个标题(h2)之前,它找到另一个分段内容元素(nav),并立即输入它,所以引用的步骤适用。
  3. 文章 仍然是当前大纲所有者当前部分,因此子步骤适用(因为当前大纲所有者 不为空)。
  4. 由于 current section (→ article) 没有标题(它还没有找到 h2),隐含的标题是创建。所以 article 有一个标题,但它不是你的 h2

我认为规范也可以在文本 ( I was surprised by this, too) 中理想地描述这一点。

验证器问题跟踪器中的相关帖子:Warning issued when headers are nested in an article

关于html - w3c 验证警告 : Article lacks heading,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50706583/

相关文章:

javascript - 我的 textArea 中的 W3C Html 验证器

html - W3 因 <noscript> 嵌套在 DIV 标记中而失败

jquery - jQuery 导航链接的事件链接颜色

jQuery addClass 属性出现然后消失

php - 如何在 PHP 中检测 w3.org 的机器人?

CSS - 供应商前缀不验证

html - 我可以在多页文档中使用多个主要元素吗?

javascript - HTML Canvas : Animation Delay

javascript - 如何从下拉列表中对表格进行排序

asp.net - 如何多行数据来自数据库