【问题标题】:When to use HTML section or article tag for a good semantic structure [closed]何时使用 HTML 部分或文章标签以获得良好的语义结构 [关闭]
【发布时间】:2021-05-30 21:52:49
【问题描述】:

我在特定页面上有以下结构和内容:

<header>
// Logo
// Site navigation
</header>
<main>
 <article>
  <section>
  // Hero image or video block
  </section>
  <section>
  // Here all kinds of paragraphs are rendered (e.g: Call to action, related video's block to this page, related actors block related to this page etc.
 // All those blocks has their own <section> tag  
  </section>
 </article>
</main>

所以在上面的例子中 &lt;article&gt; 我有 2 个 &lt;section&gt; 标签,然后在第二个 &lt;section&gt; 我有更多 &lt;section&gt; 标签嵌套。这是正确的做法吗?

【问题讨论】:

  • 嵌套部分元素是完全可以接受的,但是您需要确保这样做是有意义的。

标签: html semantics semantic-markup


【解决方案1】:

通常,article 标签将用于博客页面,用于一个页面上的多个博客文章的集合(即包含多个 &lt;article&gt; 标签),或用于单个文章页面(即包含 一个 &lt;article&gt; 标签)。无论如何,一篇文章应该在主题上独立,它的理解不依赖于文章标签之外的任何其他内容。

&lt;section&gt;s 与此类似,但更用于涵盖在特定页面(也在文章中)处理的一般主题的几个方面。在某些情况下,这两者可以互换,但总的来说,从字面上解释“文章”这个词可以帮助 IMO。

【讨论】:

  • 感谢您的确切含义:一个页面上的几篇博客文章集合。你有例子吗?
  • 这是列出博客文章的任何博客起始页面 - 有数百万篇。
猜你喜欢
  • 1970-01-01
  • 2011-03-21
  • 1970-01-01
  • 2010-09-08
  • 2012-10-28
  • 1970-01-01
  • 2015-10-11
  • 2011-04-15
  • 2015-02-21
相关资源
最近更新 更多