HTML5结构和章节或文章中的标题

bei*_*lex 5 html5

虽然我真的应该知道这一点,但我担心我不能完全理解.阅读过不同的文章,阅读书籍并与其他人交谈后,我仍然不太了解HTML5的正确结构section.h1在每个section和/或中都有一个标签是否合适article?是否新的sectionarticle构成开始h1h2再次处理?

我的印象是每个"块"应该被允许它自己的"标题"结构.

例如,这是正确的HTML5吗?:

<!doctype html>
<html>
  <head>
    <title>
    <!-- etc. etc. -->

    <body>
      <section> <!-- two or more <articles> within this section, both using <h1> tags -->
        <h1>Here is a section with articles in</h1>
        <article>
          <h1>Heading</h1>
          <h2>sub heading</h2>
          <p>A paragraph>
        </article>
        <article>
          <h1>Heading</h1>
          <h2>sub heading</h2>
          <p>A paragraph</p>
        </article>
        ...      
      </section>
      <section> <!-- two or more <articles> within this additional section, both using <h1> tags -->
        <h1>Here is a section with articles in</h1>
        <article>
          <h1>Heading</h1>
          <h2>sub heading</h2>
          <p>A paragraph>
        </article>
        <article>
          <h1>Heading</h1>
          <h2>sub heading</h2>
          <p>A paragraph</p>
        </article>
        ...      
      </section>                  
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

Bol*_*ock 4

由于 s中的每一对h1和元素分别代表一个标题和一个副标题,因此您需要将这对元素在h2articleheaderarticle为每篇文章生成正确的文档大纲。

除此之外,您各部分的标题结构看起来不错。

  • @beingalex:实际上,这取决于您使用副标题的目的:作为每篇文章的章节标题,或作为整篇文章的副标题。如果您有多个由其自己的“h2”表示的章节,您可能不想将“h1”和“h2”分组在一起。 (3认同)
  • 在决定如何使用 HTML5 构建文档时,我遇到了同样的问题。我总是回到这个参考文献 http://html5doctor.com/outlines/ 来帮助我查看文档 (2认同)