w3c html 验证错误 - 部分缺少标题。考虑使用 h2-h6 元素为所有部分添加标识标题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24155024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:01:05  来源:igfitidea点击:

w3c html validation error - Section lacks heading. Consider using h2-h6 elements to add identifying headings to all sections

htmlsemantic-markupw3c-validationsectionshtml-validation

提问by Vidhi

I am getting a warning when I try to validate my page in http://validator.w3.org:

当我尝试在以下位置验证我的页面时收到警告http://validator.w3.org

Section lacks heading. Consider using h2-h6 elements to add identifying headings to all sections.

章节没有标题。考虑使用 h2-h6 元素为所有部分添加标识标题。

My code is as below :

我的代码如下:

<section id="slider-wrapper-new">
    <div class="slider-container-new">
        // some code..
    </div>
</section>

How can I remove this error ? Do I compulsory need to add h1-h6tags inside section heading ?

我怎样才能消除这个错误?我是否需要强制添加h1-h6里面部分的标题标签?

回答by Robby Cornelissen

Either:

任何一个:

  1. Add a heading (h1, ..., h6) tag to your sectionelement.
  2. Replace your sectionelement with a divelement.
  3. Ignore the warning. The message you're seeing is a non-normativeusage recommendation, as per the HTML5 spec(highlighting mine):

    The theme of each sectionshouldbe identified, typically by including a heading (h1-h6element) as a child of the sectionelement.

  1. 向元素添加标题 ( h1, ..., h6) 标签section
  2. section用一个div元素替换你的元素。
  3. 忽略警告。根据HTML5 规范(突出显示我的),您看到的消息是非规范使用建议:

    section确定每个主题的主题,通常通过将标题(h1-h6元素)作为元素的子section元素来确定。

回答by unor

Your code is valid (if you use a closing </section>instead of </div>).

您的代码是有效的(如果您使用结束语</section>而不是</div>)。

The W3C validator reports a warning, not an error.

W3C 验证器报告警告,而不是错误。

While it is useful to provide a heading for each sectioning content element, it is not required.

虽然为每个分节内容元素提供标题很有用,但这不是必需的

The only way to prevent this warning when using sectioning content elements is, well, to follow the advice by providing a heading content element. If you'd use a divinstead, your document outline would be different and likely wrong (if you used sectioncorrectly in the first place).

在使用分段内容元素时防止出现此警告的唯一方法是通过提供标题内容元素来遵循建议。如果您使用 adiv代替,您的文档大纲将会不同并且可能是错误的(如果您section首先正确使用)。

回答by Carlos

You have to put an h1,h2,h3 inside your section:

您必须在您的部分中放置 h1,h2,h3 :

<section id="slider-wrapper-new">
 <div class="slider-container-new">
  <h3>My Title</h3>
    // some code..
 </div>