[英]How to use <section> and <article> tags in HTML5?
I just confused how to use <article>
and <section>
tags in HTML5. 我只是混淆了如何在HTML5中使用<article>
和<section>
标记。
I referenced lot in Google and also in Stack Overflow website. 我在Google和Stack Overflow网站中都引用过很多。
On that, I found HTML5 pages with <section>
elements containing <article>
elements, and <article>
elements containing <sections>
elements. 在此基础上,我发现HTML5页面的<section>
元素包含<article>
元素,而<article>
元素包含<sections>
元素。
I also found pages with <section>
elements containing <section>
elements, and <article>
elements containing <article>
elements. 我还发现了带有<section>
元素的页面,这些元素包含<section>
元素,而<article>
元素包含<article>
元素。
What is the exact use of these tags? 这些标签的确切用途是什么?
It depends on your content. 这取决于您的内容。
For example, a list of recent blog posts could be a section
containing several article
(example 1), a complex blog post could be an article
with several section
(example 2), a blog post with comments could be an article
with a section
and several article
(example 3). 例如,最近的博客文章列表可以是包含多个article
的section
(示例1),复杂的博客文章可以是具有多个section
的article
(示例2),带有评论的博客文章可以是具有section
的article
,几篇article
(示例3)。
How to decide when to use which? 如何决定何时使用哪个? Easy: 简单:
section
. 如果需要分段内容元素,请从section
开始。 nav
. 检查内容是否符合nav
的定义 。 If yes, go with nav
, else: 如果是,请使用nav
,否则: aside
. 检查内容是否符合aside
的定义 。 If yes, go with aside
, else: 如果是,请aside
,否则: article
. 检查内容是否符合article
的定义 。 If yes, go with article
, else: 如果是,请转到article
,否则: section
. 待在section
。 Example 1: A list of blog posts 示例1:博客文章列表
<section>
<h2>Recent blog posts</h2>
<article>
<h3>Blog post 1</h3>
</article>
<article>
<h3>Blog post 2</h3>
</article>
</section>
Example 2: A complex blog post 示例2:复杂的博客文章
<article>
<h2>Blog post 1</h2>
<section>
<h3>So, this is what happened</h3>
</section>
<section>
<h3>What the others said</h3>
</section>
</article>
Example 3: A blog post with comments 示例3:带有评论的博客文章
<article>
<h2>Blog post 2</h2>
<section>
<h3>Comments</h3>
<article>
<p>First!</p>
</article>
<article>
<p>First! <ins>Edit: Second :(</ins></p>
</article>
</section>
</article>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.