嵌套<article>标签在语义上是否正确?

9

我一直在研究HTML5的新元素及其适当的使用方法,目前我有一些类似这样的标记:

    <article>
        <h1>Crazy Awesome Programming Projects</h1>
        <article>
            <h2>Mathematics</h2>
            
            <section>
                <h3>Binary to Decimal converter</h3>
                <p> info here </p>
            </section>
            
            <section>
                <h3>Scientific Calculator</h3>
                <p> info here </p>
            </section>
            
        </article>
        
        <article>
            <h2>String Manipulation</h2>
            
            <section>
                <h3>RSS Feed Generator</h3>
                <p> info here </p>
            </section>

            <section>
                <h3>Palindrome Detector</h3>
                <p> info here </p>
            </section>
        </article>
    </article>

在这种方式下嵌套<article>标签是否语义上正确?

2个回答

13

有些情况下,嵌套article元素是正确的,其中最突出的情况是针对博客文章的评论。

但我认为你的例子不是这种情况(尽管没有看到完整的内容很难确定)。

我会完全相反地做:

<section> <!-- probably not article -->
    <h1>Crazy Awesome Programming Projects</h1>

    <section> <!-- not article -->
        <h2>Mathematics</h2>

        <article> <!-- not section -->
            <h3>Binary to Decimal converter</h3>
            <p> info here </p>
        </article>

        <article> <!-- not section -->
            <h3>Scientific Calculator</h3>
            <p> info here </p>
        </article>

    </section>

    <section> <!-- not article -->
        <h2>String Manipulation</h2>

        <article> <!-- not section -->
            <h3>RSS Feed Generator</h3>
            <p> info here </p>
        </article>

        <article> <!-- not section -->
            <h3>Palindrome Detector</h3>
            <p> info here </p>
        </article>
    </section>
</section>
“二进制转十进制转换器”,“科学计算器”,“RSS Feed生成器”和“回文检测器”是这里的文章。它们是“自包含组成部分”,并且在原则上是可以独立分发或重用的,例如在合集中。
“数学”和“字符串操作”是类别。
在结构上,它类似于网店。“回文检测器”将是可购买的产品,而“字符串操作”将是产品类别。我想你不会把产品类别视为“自包含组成部分”。
对于容器(“Crazy Awesome Programming Projects”),只有当有更多内容提供上下文时,才能使用 article。否则,它只是一个顶级类别,包含子类别,其中包含“真正”的内容。
确定是否适合使用article 的好问题:
- 内容是否具有自己的发布日期? - 内容是否可能由不同的作者撰写? - 内容是否可以作为一个单独的条目进入feed? - 如果没有任何其他内容/上下文,该内容是否仍然有意义?
如果这些问题的答案是“是”,则可能正确使用 article

11

是的,根据HTML5规范。关于嵌套article元素,规范中有如下说明:

当嵌套

元素时,内部的
元素代表与外部文章内容相关的文章。例如,在接受用户提交评论的网站上的博客文章可以将评论表示为嵌套在博客文章的
元素中。


啊,感谢Marc Baumbach的快速回复!我现在感觉有点儿傻,完全错过了文档中的那篇文章。我需要更好地阅读文档。 - Sho Kei
1
也许你会感兴趣:目前公共HTML工作组邮件列表上有一个活跃的讨论串(http://lists.w3.org/Archives/Public/public-html/2013Jan/0109.html)关于这个问题。 - steveax
另一个适用的好例子是博客文章(外部文章)和食谱(内部文章)。 - Josh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接