简体   繁体   English

HTML5 - 正确使用 <article> 标签

[英]HTML5 - Correct usage of the <article> tag

Reading an article on the <article> tag on HTML5, I really think my biggest confusion is in the first question of this section: 阅读文章<article> HTML5的标签,我真的觉得我最大的困惑是在本节的第一个问题:

Using <article> gives more semantic meaning to the content. 使用<article>为内容提供了更多的语义含义。 By contrast <section> is only a block of related content, and <div> is only a block of content... To decide which of these three elements is appropriate, choose the first suitable option: 相比之下, <section>只是一个相关内容块, <div>只是一个内容块...要确定这三个元素中哪一个是合适的,请选择第一个合适的选项:

  1. Would the content would make sense on its own in a feed reader? 内容在Feed阅读器中是否有意义? If so, use <article> . 如果是这样,请使用<article>
  2. Is the content related? 内容是否相关? If so, use <section> . 如果是这样,请使用<section>
  3. Finally, if there's no semantic relationship, use <div> . 最后,如果没有语义关系,请使用<div>

So I guess my question is really: What types of content belong in a feed reader? 所以我想我的问题是: 饲料阅读器中有哪些类型的内容?

The spec answers this quite clearly: 规范很清楚地回答了这个问题:

The article element represents a self-contained composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, eg in syndication. article元素表示文档,页面,应用程序或站点中的自包含组合,并且原则上可独立分发或可重用,例如在联合中。 This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content. 这可以是论坛帖子,杂志或报纸文章,博客条目,用户提交的评论,交互式小部件或小工具,或任何其他独立的内容项。

see: http://dev.w3.org/html5/spec/Overview.html#the-article-element 请参阅: http//dev.w3.org/html5/spec/Overview.html#the-article-element

You've brought up a good argument and yes the spec does rather clearly define <article> as a syndication-worthy collection of content. 你提出了一个很好的论据,是的,规范确实明确地将<article>定义为一个有价值的联合内容集合。 The way I see it, your article would be the composed blog post – what you as the content writer of the site produce. 我看到它的方式,你的文章将是组成的博客文章 - 你作为网站的内容编写者产生的。 While comments on that section are related to the article, they are not, in fact, part of the article, and should be relegated to another block in the <section> , either a non-semantic <div> or simply <p> s with display:block set. 虽然对该部分的评论与文章有关,但事实上它们并不是文章的一部分,应该降级到<section>中的另一个块,要么是非语义<div>要么只是<p> s带display:block集。 This is a decision that's left to the designer, depending on how they semantically evaluate the worth of the commentary. 这是一个留给设计师的决定,取决于他们如何在语义上评估评论的价值。

Remember too that you have the <aside> tag, which is almost tailor-made for commentary, whether from the author or from the reader. 还要记住,你有<aside>标签,它几乎是为评论量身定做的,无论是来自作者还是来自读者。

The W3C spec leaves a lot open to interpretation and it ultimately comes down to the author's opinion. W3C规范为解释留下了很多空间,最终归结为作者的观点。 Here is a short and simple answer in the form of a question: 以下是一个问题形式的简短答案:

What are the primary significant pieces of content you want to share on the page? 您要在页面上分享的主要重要内容是什么?

Here are a few examples: 这里有一些例子:

  • On this very page, each answer could be an article. 在这个页面上, 每个答案都可以是一篇文章。
  • On flickr each photo displayed in the photostream could be considered an article. 在flickr上, 照片流中显示的每张照片都可以被视为一篇文章。
  • On dribbble each shot displayed on the page could be an article. 在运球时,页面上显示的每一个镜头都可能是一篇文章。
  • On google each search result listed could be an article. 在谷歌上列出的每个搜索结果可能是一篇文章。
  • On a blog each article.. well each article could be an article. 在博客上每篇文章......每篇文章都可以是一篇文章。
  • On a blog page with an article and a series of comments you could have two major sections. 在包含文章和一系列评论的博客页面上,您可以有两个主要部分。 One with an article and another for comments in which each comment could be considered an article. 一篇文章和另一篇文章评论,其中每篇评论都可以被视为文章。

It's the author's discretion as to how far they want to go. 作者可以自行决定他们想走多远。 Most blog authors have an RSS feed for their articles, but others may also provide feeds for comments, and shared links. 大多数博客作者都有自己的文章的RSS提要,但其他人也可能提供评论和共享链接的提要。

A lot of people have written on this subject. 很多人都写过这个主题。 For further information I highly recommend reading: 有关详细信息,我强烈建议阅读:

Most feed readers can handle many types of content, it could include copy, images, videos, etc. The feed for your will include the content on your site that is repeated or includes multiple versions. 大多数Feed阅读器可以处理多种类型的内容,它可能包括副本,图像,视频等。您的遗嘱包括您网站上重复或包含多个版本的内容。 A question and answer site will have a feed of new questions. 问答网站将提供新问题。 A video sharing site will have a feed of new videos. 视频共享网站将提供新视频。 A software review site will have a feed of new software or new reviews. 软件评论网站将提供新软件或新评论。

I'd recommend considering what the typical consumer of your content would want to find easily in their feed reader. 我建议考虑一下您的内容的典型消费者希望在他们的Feed阅读器中轻松找到的内容。 You get to define what types of content belong in a feed reader. 您可以定义Feed阅读器中的内容类型。

A feed reader, in general, should contain a list of stories. 通常,提要阅读器应包含故事列表。 Look at http://google.com/elections/ - it's a good example of the sort of thing a feed reader might contain. 请参阅http://google.com/elections/ - 这是Feed阅读器可能包含的一个很好的例子。 The important part is that all the stories are self-contained, and in theory do not need to be related at all. 重要的是,所有的故事都是独立的,理论上根本不需要相关。

div元素可以用新元素替换:header,nav,section,article,aside和footer。

The markup for that document could look like the following: 该文档的标记可能如下所示:

<body>
     <header>...</header>
     <nav>...</nav>
     <article>
          <section>
               ...
          </section>
     </article>
     <aside>...</aside>
     <footer>...</footer>
</body>

You may find more information in this article on A List Apart . 您可以在A List Apart上找到有关此文章的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM