【问题标题】:How exactly do the semantics of the HTML5 <header>, <section>, and <footer> tags work?HTML5 <header>、<section> 和 <footer> 标签的语义究竟是如何工作的?
【发布时间】:2011-04-17 09:43:22
【问题描述】:

我有点困惑我应该如何使用 HTML5 &lt;header&gt;&lt;section&gt;&lt;footer&gt; 标签。目前,我无法确定是否像这样使用它们:

<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 以显示这些部分的预期含义。我意识到它们是不必要的。哪种方法是正确的?

【问题讨论】:

    标签: html semantics semantic-markup


    【解决方案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>
    

    几个最佳实践和 tuts 链接

    【讨论】:

    【解决方案2】:

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

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

    像这样在一篇文章中包含不同的部分感觉很自然。

    【讨论】:

    • 最好用这种方式来规范section和article的意思。对此帖子 +1。
    【解决方案3】:

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

    【讨论】:

      【解决方案4】:

      它们都有道理,但总的来说,第一个是最正确的。

      假设整个 sn-p 代表一个真实的部分(关于同一主题的内容),那么在部分本身内部有一个页眉和一个页脚是有意义的。此外,一个部分需要一个标题(h1-6,至少一个。如果超过一个,则可能带有一个 hgroup),并且您的第二个和第三个示例中缺少它。

      【讨论】:

        猜你喜欢
        • 2011-03-03
        • 2018-05-21
        • 2011-06-26
        • 2021-08-15
        • 2012-06-08
        • 2011-10-11
        • 2013-07-05
        • 1970-01-01
        相关资源
        最近更新 更多