HTML5 <header>,<section>和<footer>标签的语义究竟是如何工作的?

Eri*_*ric 4 html5 semantic-markup semantics

我有点疑惑,我应该如何使用HTML5 <header>,<section>和<footer>标签.目前,我无法确定是否像这样使用它们:

<section id="example_section">
    <header>
        <h1>Example Section</h1>
        <p>etc</p>
    </header>

    <p>Content para 1</p>
    <p>Content para 2</p>
    <p>Content para 3</p>

    <footer>
        Wasn't that swell?
    </footer>
</section>
Run Code Online (Sandbox Code Playgroud)

或者像这样:

<header>
    <h1>Example Section</h1>
    <p>etc</p>
</header>

<section id="example_section">
    <p>Content para 1</p>
    <p>Content para 2</p>
    <p>Content para 3</p>
</section>

<footer>
    Wasn't that swell?
</footer>
Run Code Online (Sandbox Code Playgroud)

或妥协,像这样:

<section id="example_section_wrapper">
    <header>
        <h1>Example Section</h1>
        <p>etc</p>
    </header>
    <section id="example_section">
        <p>Content para 1</p>
        <p>Content para 2</p>
        <p>Content para 3</p>
    </section>
    <footer>
        Wasn't that swell?
    </footer>
</section>
Run Code Online (Sandbox Code Playgroud)

我已经包含了ID以显示这些部分的预期含义.我意识到他们是不必要的.哪种方法正确?

Pra*_*pta 7

一切都是正确的,但这比其他任何一个都好

<section id="example_section_wrapper">
    <header>
        <h1>Example Section</h1>
        <p>etc</p>
    </header>
    <section id="example_section">
        <p>Content para 1</p>
        <p>Content para 2</p>
        <p>Content para 3</p>
    </section>
    <footer>
        Wasn't that swell?
    </footer>
</section>
Run Code Online (Sandbox Code Playgroud)

几个最佳实践和tuts链接

  • 从一个说"比其他任何人更好"的人那里接受语义建议是一个好主意吗?(**+ 1**) (6认同)
  • @Eric:请参阅http://html5doctor.com/avoiding-common-html5-mistakes/和http://html5doctor.com/downloads/h5d-sectioning-flowchart.png. (2认同)