简体   繁体   English

w3c html验证错误 - 部分缺少标题:嵌套元素中可用的h2

[英]w3c html validation error - Section lacks heading: where h2 available in nested element

Am trying to write valid html by following w3c standards. 我试图按照w3c标准编写有效的html。 But getting warning on below code as Section lacks heading. Consider using h2-h6 elements to add identifying headings to all sections 但是由于Section lacks heading. Consider using h2-h6 elements to add identifying headings to all sections在下面的代码上收到警告Section lacks heading. Consider using h2-h6 elements to add identifying headings to all sections Section lacks heading. Consider using h2-h6 elements to add identifying headings to all sections . Section lacks heading. Consider using h2-h6 elements to add identifying headings to all sections But I have used <h2> in my section, then why am I getting this and how can I overcome? 但我在我的部分中使用过<h2> ,那为什么我会得到这个,我怎么能克服?

<section id="section1">
  <article class="container">
    <h2>Some heading</h2>
  </article>
</section>

Your <article> contains a heading, but your <section> does not, because your <h2> is associated with your <article> , not your <section> . 您的<article>包含标题,但<section>没有,因为您的<h2><article>相关联,而不是<section>

If your <section> is just a generic container and not an actual distinct section of articles in your page, it should be a <div> instead, or a <main> if it's the only container in your page (but judging by the section ID it's probably safe to assume it isn't). 如果您的<section>只是一个通用容器,而不是页面中实际不同的文章部分,那么它应该是<div> ,如果它是页面中唯一的容器,则应为<main> (但是按部分判断) ID可能是安全的,假设它不是)。 Alternatively, your <article> should be a <div> instead as "container" is a rather oddly generic class name for such an element. 或者,您的<article>应该是<div>而不是“container”是这种元素的一个相当奇怪的通用类名。

Note that sections missing headers is not an error but a warning; 请注意,缺少标题的部分不是错误,而是警告; you are free to leave your <section> without a heading, it will just look strange in the document outline. 你可以自由地离开<section>而没有标题,它在文档大纲中看起来很奇怪。 Nevertheless, the warning is there to indicate that you may have either left out a heading, or you may be misusing sectioning elements. 然而,警告是指示您可能遗漏了标题,或者您可能滥用分段元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM