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

时间:2010-09-26 12:50:13

标签: html5 semantics semantic-markup

我有点困惑,我应该如何使用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>

或者像这样:

<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 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>

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

4 个答案:

答案 0 :(得分: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>

一些最佳实践和最佳链接

答案 1 :(得分:1)

一个部分可以包含一个部分,但更好的通用容器是实际的文章。而不是:

<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>

您可能想要使用它:

<article>
    <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>
</article>

像这样,在一篇文章中有各种各样的部分是很自然的。

答案 2 :(得分:0)

标签本身非常抽象,现在。您可以通过上述任何方式使用它们,但您的第三个选项是最正确的。

答案 3 :(得分:0)

它们都有意义,但第一个是最正确的。

假设整个片段代表一个真实的片段(关于同一主题的内容),它有意义的是在片段本身内部有一个页眉和一个页脚。另外一个部分需要一个标题(h1-6,至少一个。如果不止一个,可能还有一个hgroup),你的第二个和第三个例子中缺少它。