且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在HTML5中,***使用< section>和< h1>而不是< h2> - < h6>?

更新时间:2022-12-01 09:03:30

似乎该规范甚至声明h1优先于所有其他:

It seems that the spec even states that h1 has preference over all the others:


章节可能包含任何等级的标题,但强烈建议作者要么只使用h1元素,要么使用适当等级的元素作为该部分的嵌套级别。

Sections may contain headings of any rank, but authors are strongly encouraged to either use only h1 elements, or to use elements of the appropriate rank for the section's nesting level.

然而令我不安的是:


还鼓励作者明确地将部分包含在切片内容的元素中,而不是依赖于在分区内容的一个元素中包含多个标题而生成的隐式部分。

Authors are also encouraged to explicitly wrap sections in elements of sectioning content, instead of relying on the implicit sections generated by having multiple headings in one element of sectioning content.

现在我们得到的部分,文章很精彩,导航和旁边用来防止div-itis。但是如果我们需要为每个部分明确地使用section元素而不是我们最终有更多的section元素,那么我们就有了div。我觉得有一个很好的例子,它会出现。

Now it is wonderful that we got section, article, nav and aside to use to prevent div-itis. But if we need to explicitly use a section element for each section than we end up with more section elements then we ever had divs. I feel a strong case of section-itis coming on.