应该< sections>有< articles>或者< articles>有< sections>吗? [英] Should <sections> have <articles> or should <articles> have <sections>?

查看:54
本文介绍了应该< sections>有< articles>或者< articles>有< sections>吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读Mark Pilgirm的"深入HTML5 语义部分,它讨论了HTML5如何引入<article><section>元素.它说<section>代表通用文档或部分,而<article>代表独立的组成.无论哪种方式,我都看不到逻辑语义上的父子关系.

I'm reading Mark Pilgirm's "Dive into HTML5" and in the semantics section, it talks about how HTML5 introduces the <article> and <section> elements. It says that <section>s represent a generic document or section, while <article>s represent a self-contained composition. I don't see a logically semantic parent-child relationship either way.

我尝试通过 HTML5 Outliner 运行以下代码,它似乎表明该文档的轮廓不管它们如何嵌套,结果都是一样的.

I tried running the following code through the HTML5 Outliner and it seemed to indicate that the document outline comes out the same, no matter how they were nested.

所以我的问题是:<section>应该嵌套在<article> s内部,还是<article>应该嵌套在<secion> s内部,还是从语义角度来看都没关系?

So my question is: should <section>s be nested inside <article>s, should <article>s be nested inside <secion>s, or does it not matter from a semantic view point?

<section><h1>section article?</h1>
  <article><h1>art 1</h1></article>
  <article><h1>art 2</h1></article>
  <article><h1>art 3</h1></article>
</section>

<article><h1>article section?</h1>
  <section><h1>sec 1</h1></section>
  <section><h1>sec 2</h1></section>
  <section><h1>sec 3</h1></section>
</article>

推荐答案

以任何一种方式嵌套它们是完全可以接受的.尽管文档大纲没有区分<section><article>,但是从语义的角度来看,它们是两个不同的东西.这就是将它们作为两个不同的语义元素进行介绍的全部要点.

It's entirely acceptable to nest them either way. Although the document outline does not distinguish between a <section> and an <article>, from a semantic point of view they are two different things. That's the whole point of introducing them as two distinct semantic elements.

如果您的页面包含多篇文章,请使用第一个代码段.

Use the first snippet if your page consists of multiple articles.

当您的文章足够全面以包含多个部分时,请使用第二个片段.

Use the second snippet when you have an article that's comprehensive enough to contain multiple sections.

如果两者都适合您的内容,则您甚至可以将它们组合在一起,从而使标记看起来像这样:

You can even combine them both if using both fits your content, such that your markup looks like this:

<section><h1>section article?</h1>
  <article><h1>art 1</h1>
    <section><h1>sec 1.1</h1></section>
    <section><h1>sec 1.2</h1></section>
    <section><h1>sec 1.3</h1></section>
  </article>
  <article><h1>art 2</h1>
    <section><h1>sec 2.1</h1></section>
    <section><h1>sec 2.2</h1></section>
    <section><h1>sec 2.3</h1></section>
  </article>
  <article><h1>art 3</h1>
    <section><h1>sec 3.1</h1></section>
    <section><h1>sec 3.2</h1></section>
    <section><h1>sec 3.3</h1></section>
  </article>
</section>

这篇关于应该&lt; sections&gt;有&lt; articles&gt;或者&lt; articles&gt;有&lt; sections&gt;吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆