【问题标题】:HTML5 semantic markup for main contents heading主要内容标题的 HTML5 语义标记
【发布时间】:2012-05-08 17:37:02
【问题描述】:

我再次向你寻求帮助,Stack Overflow。这次我很难理解 HTML5 关于我网站主要内容标题的语义。下面是两个例子,我应该使用哪一个?也许我应该走一条完全不同的路?

编辑:我混淆了代码示例!

示例 1

使用此代码,我得到如下大纲:

  1. 类别:foo
  2. 博文#1
  3. 博文#2

这似乎不正确,因为博客文章是在该类别下发布的?

<header id="header">
    <h1>My awesome website!</h1>
    <!-- Primary navigation and such -->
</header>
<div id="content">
    <section id="title">
        <h1>Category: foo</h1>
        <p>Some content</p>
    </section>
    <article>
        <h1>Blog post #1</h1>
        <p>Some content</p>
    </article>
    <article>
        <h1>Blog post #2</h1>
        <p>Some content</p>
    </article>
</div>

示例 2

使用此代码,我得到如下大纲:

  1. 类别:foo
    1. 博文#1
    2. 博文#2

这对我来说似乎是正确的,但 HTML5 Doctor 表示不应将 &lt;section&gt; 用作主要/主要内容包装器。

另外,如果我要使用这个示例,如果主要内容没有自然标题(例如显示所有帖子的索引页面),我会将&lt;section id="content&gt;&lt;div id="content"&gt; 交换吗?

<header id="header">
    <h1>My awesome website!</h1>
    <!-- Primary navigation and such -->
</header>
<section id="content">
    <header id="title">
        <h1>Category: foo</h1>
        <p>Some content</p>
    </header>
    <article>
        <h1>Blog post #1</h1>
        <p>Some content</p>
    </article>
    <article>
        <h1>Blog post #2</h1>
        <p>Some content</p>
    </article>
</section>

【问题讨论】:

    标签: wordpress html


    【解决方案1】:

    尝试以老式方式使用 h1-h6 标签。

    <h1>My awesome website!</h1>
    
    <section> 
    
        <h2>Category: foo</h2>
        <p>Some content</p>
    
        <article>
            <h3>Blog post #1</h3>
            <p>Some content</p>
        </article>
    
       <article>
           <h3>Blog post #2</h3>
           <p>Some content</p>
       </article>
    </section>
    
    <section>  
        <h2>Category: bar</h2>
        <p>some content</p>
    
        <article>
            <h3>Blog post #3</h3>
            <p>Some content</p>
        </article>
    
        <article>
           <h3>Blog post #4</h3>
           <p>Some content</p>
        </article>
    </section>     
    

    这类似于包含&lt;article&gt;s 的&lt;section&gt;HTML5Doctor's own example

    从技术上讲,您可以将&lt;h2&gt;&lt;h3&gt; 标记替换为&lt;h1&gt;,这同样有效。使用 h1-h6 的优点是保持与旧用户代理(尤其是屏幕阅读器)的向后兼容性。

    【讨论】:

    • 你有关于何时&lt;h1&gt; 应该替换&lt;h3&gt; 的断言的来源吗?规范是here,我找不到任何支持它的东西。
    • 这就是为什么你会使用 h1 的一个例子。我并不是要暗示这是唯一正当的理由。就 HTML5 而言,这真的无关紧要。
    【解决方案2】:

    这可能会对您有所帮助:http://visitmix.com/writings/article-vs-section-weve-finally-gone-mad

    看起来像你想要的

    <section id="content">
        <h1>Category: foo</h1>
        <p>Some content</p>
      <article>
        <h1>Blog post #1</h1>
        <p>Some content</p>
      </article>
      <article>
        <h1>Blog post #2</h1>
        <p>Some content</p>
      </article>
    </section>
    

    【讨论】:

    • 是的,我喜欢这个,在这种情况下我不反对使用section标签......我唯一不太明白的是为什么你们都害怕使用h2(甚至是文章中的 h3) 标签?这是我唯一会改变的。
    【解决方案3】:

    我会像@Patrick McElhaney 所做的那样标记页面——每个类别都有一个SECTION。我刚刚添加了另一个名为“内容”的包装器,以允许对子内容元素进行分组。这反映了您的原始布局。

    <header id="header">
        <h1>My awesome website!</h1>
        <!-- Primary navigation and such -->
    </header>
    
    <section id="content">
        <section class="category" id="catFoo">
            <hgroup id="title">
                <h2>Category: Foo</h2>
                <p>Category Description</p>
            </hgroup>
            <article>
                <h3>Blog post #Foo1</h3>
                <p>Some content</p>
            </article>
            <article>
                <h3>Blog post #Foo2</h3>
                <p>Some content</p>
            </article>
        </section>
    
        <section class="category" id="catBar">
            <hgroup id="title">
                <h2>Category: Bar</h2>
                <p>Category Description</p>
            </hgroup>
            <article>
                <h3>Blog post #Bar1</h3>
                <p>Some content</p>
            </article>
        </section>
    </section>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-02
      • 1970-01-01
      • 2019-02-15
      • 1970-01-01
      • 1970-01-01
      • 2013-08-28
      相关资源
      最近更新 更多