简体   繁体   English

如何使用 <section> 和 <article> HTML5中添加标签?

[英]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). 例如,最近的博客文章列表可以是包含多个articlesection (示例1),复杂的博客文章可以是具有多个sectionarticle (示例2),带有评论的博客文章可以是具有sectionarticle ,几篇article (示例3)。

How to decide when to use which? 如何决定何时使用哪个? Easy: 简单:

  1. If you need a sectioning content element, start with section . 如果需要分段内容元素,请从section开始。
  2. Check if the content matches the definition of nav . 检查内容是否符合nav定义 If yes, go with nav , else: 如果是,请使用nav ,否则:
  3. Check if the content matches the definition of aside . 检查内容是否符合aside定义 If yes, go with aside , else: 如果是,请aside ,否则:
  4. Check if the content matches the definition of article . 检查内容是否符合article定义 If yes, go with article , else: 如果是,请转到article ,否则:
  5. Stay with 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.

相关问题 如何正确使用HTML5标签的文章和章节? - How to proper use HTML5 tags Article and Section? 在HTML5中,我应该使用文章或部分标签来制作标签吗? - In HTML5 should I use article or section tags to make tabs? HTML5有新的标签文章,部分和旁边。我什么时候应该使用div标签? - HTML5 has new tags article, section and aside. When should I use div tag? 文章,第html5部分语义 - Article , section html5 semantics HTML5 - 文章内部 - HTML5 - Section inside article 如何在html5中的标题,部分,文章等中使用h1到h6? - How to use h1 to h6 within header, section, article, etc.. in html5? CodedUI GetChildren()不返回带有HEADER,SECTION,ARTICLE,NAV等HTML5标签的子级 - CodedUI GetChildren() doesn't return children with HTML5 tags like HEADER, SECTION, ARTICLE, NAV 使用HTML5标签有什么好处 <article> , <section> , <figure> , <header> , <footer> , <nav> ? - What is the benefit of using HTML5 tags like <article>, <section>, <figure>, <header>, <footer>, <nav>? 在引擎盖下,HTML5标签(文章,部分,旁边,页眉,页脚)是否像div一样实现? - Under the hood, are HTML5 tags (article, section, aside, header, footer) implemented just like div? HTML5结构和章节或文章中的标题 - HTML5 structure and headings in section or article
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM