【问题标题】:Is it semantically correct to nest <article>s?嵌套 <article> 在语义上是否正确?
【发布时间】:2013-01-17 11:36:35
【问题描述】:

我一直在阅读新的 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>

以这种方式嵌套&lt;article&gt;标签在语义上是否正确?

【问题讨论】:

    标签: html semantics


    【解决方案1】:

    在某些情况下嵌套article 元素是正确的;最突出的案例是博客文章的 cmets。

    但我认为您的示例并非如此(不过,如果没有看到完整的内容,很难做出决定)。

    我会完全相反:

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

    “Binary to Decimal converter”、“Scientific Calculator”、“RSS Feed Generator”和“Palindrome Detector”是这里的文章。它们是“一个独立的组合”和“原则上,可以独立分发或重复使用,例如在联合中”。

    “数学”和“字符串操作”是类别。

    在结构上类似于网上商店。 “Palindrome Detector”将是可购买的产品,而“String Manipulation”将是产品类别。我猜你不会认为产品类别是“独立的”。

    对于容器(“Crazy Awesome Programming Projects”),我会使用article,只有在有更多内容提供上下文的情况下。否则它只是一个顶级类别,包含子类别,其中包含“真实”内容。

    article是否合适的好问题:

    • 可以内容有自己的发布日期吗?
    • 是否可以内容的作者与页面不同?
    • 可以内容是供稿中的单独条目吗?
    • 如果在没有任何其他内容/上下文的情况下打印出来,内容是否仍然有意义?

    如果(部分)这些问题的回答是“是”,article 可能是正确的。

    【讨论】:

      【解决方案2】:

      是的,根据HTML5 spec。这就是嵌套article 元素的说法:

      当文章元素嵌套时,内层文章元素代表原则上与外层文章内容相关的文章。例如,接受用户提交的 cmets 的网站上的博客条目可以将 cmets 表示为嵌套在博客条目的 article 元素中的文章元素。

      【讨论】:

      • 啊,感谢 Marc Baumbach 的快速回复!我现在觉得有点傻,完全错过了文档中的那篇文章。我需要在更彻底地阅读文档方面做得更好..
      • 可能感兴趣:这里有一个active thread on the public HTML working group mailing list 正在讨论这个问题。
      • 另一个合适的例子是博客文章(外部文章)和食谱(内部文章)。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-13
      • 2019-07-18
      • 2011-06-13
      相关资源
      最近更新 更多