简体   繁体   English

我应该使用<ol>,<ul>,<article>或<blockquote>来使用语义HTML进行评论吗?

[英]Should I use <ol>, <ul>, <article> or <blockquote> for comments listing using semantic HTML?

I made some research and didn't find an appropriate answer. 我做了一些研究,没有找到合适的答案。 I'm wondering if it's better to keep using li elements for a comments listing or maybe switch to the article element? 我想知道是否最好继续使用li元素作为评论列表或者切换到文章元素?

Example 1: 例1:

<ol class="comment-list">
  <li class="comment">
    <figure class="avatar">
      <img ... >
    </figure>
    <span class="author">Linus Torvalds</span>
    <p class="comment-text">
      Linux is awesome!
    </p>
  </li>
  ...
</ol>

Example 2: 例2:

<div class="comment-list">
  <article class="comment">
    <header>
      <figure class="avatar">
        <img ... >
      </figure>
    </header>
    <span class="author">Linus Torvalds</span>
    <p class="comment-text">
      Linux is awesome!
    </p>
  </article>
  ...
</div>

What is the best solution? 什么是最好的解决方案?

UPDATE 1 更新1

Example 3 (a better example): 例3(一个更好的例子):

<main>
  <article>

    <header>
      <h1>Text title</h1>
    </header>

    <p>The text...</p>

    <section class="comment-list">
      <article class="comment">
        <header>
          <figure class="avatar">
            <img ... >
          </figure>
        </header>
        <span class="author">Linus Torvalds</span>
        <p class="comment-text">
          Linux is awesome!
        </p>
      </article>
      <article class="comment">
        <header>
          <figure class="avatar">
            <img ... >
          </figure>
        </header>
        <span class="author">Richard Stallman</span>
        <p class="comment-text">
          GNU is awesome!
        </p>
      </article>
      ...
    </section>

  </article>
</main>

If you want to provide more semantic value than you would using ol / ul , then article would be the best option in my opinion. 如果你想提供比使用ol / ul更多的语义价值,那么article将是我认为最好的选择。

About blockquote from w3schools : 关于来自w3schools的 blockquote

The <blockquote> tag specifies a section that is quoted from another source. <blockquote>标记指定从其他来源引用的部分。

I would say that "quoted from another source" does not really apply to comments. 我会说“引自其他来源”并不真正适用于评论。

About article from w3schools : 关于来自w3schools的 article

The <article> tag specifies independent, self-contained content. <article>标记指定独立的自包含内容。 An article should make sense on its own and it should be possible to distribute it independently from the rest of the site. 一篇文章本身应该有意义,应该可以独立于网站的其他部分分发它。

All of these points probably apply to your comments, so I would recommend going with <article> . 所有这些要点可能都适用于您的评论,因此我建议您使用<article>

Edit 编辑

OK, here's the gory details EMPHASIS is mine 好的,这是血腥的细节 EMPHASIS是我的

<figure> and <figcaption> <figure><figcaption>

Usually a <figure> is an image , illustration, diagram, code snippet, etc., that is referenced in the main flow of a document, but that can be moved to another part of the document or to an appendix without affecting the main flow. 通常, <figure>图像 ,插图,图表,代码片段等, 文档的主流程引用 ,但可以移动到文档的另一部分或附录而不影响主流程。

... ...

A caption can be associated with the <figure> element by inserting a <figcaption> inside it (as the first or the last child) 通过在其中插入<figcaption> (作为第一个或最后一个子元素),可以将标题与<figure>元素相关联

<figure> - MDN <figure> - MDN

What I see is an image of an author. 我看到的是作者的形象。 if it was taken out of context ( flow ), is it still an image of the author? 如果它脱离了上下文( 流程 ),它仍然是作者的形象吗? Yes, it is. 是的。 How? 怎么样? Because it has the has the <figcaption> tag as its last child and the name of the author as it's text. 因为它有<figcaption>标签作为其最后一个子项,并且作者的名称是文本。


<header>

The HTML element represents introductory content, typically a group of introductory or navigational aids . HTML元素表示介绍性内容,通常是一组介绍性或导航性辅助

... ...

The element is not sectioning content and therefore does not introduce a new section in the outline . 元素不是对内容进行分区 ,因此不会在大纲中引入新的部分

<header> - MDN <header> - MDN

Either wrap <h1-h6> or <nav> in <header> , if it's a <nav> then it's outside of <main> and inside of <main> if it's for headings ( <h1-h6> ). 任一包裹<h1-h6><nav><header> ,如果它是一个<nav>那么它的外面的<main>和内<main>如果它是标题( <h1-h6> Do not wrap <header> around <figure> . 不要在<figure>周围包裹<header> <figure> <figure> is a specialized content wrapper , not content. <figure>是一个专门的内容包装器 ,而不是内容。 <header> is a specialized content wrapper . <header>是一个专门的内容包装器


<article> and <section> <article><section>

<article> and <section> can be nested within each other in either direction but stick to one pattern. <article><section>可以在任何一个方向上相互嵌套,但坚持一个模式。 Basically <article> can be a sub-topic of <article> or <section> or vice versa. 基本上<article>可以是<article><section>的子主题,反之亦然。

Refer to: Using HTML Sections and Outlines , <article> tag , and <section> tag . 请参阅:使用HTML部分和大纲<article>标记<section>标记


Even though there are 2 versions of HTML5 tag definitions ( W3C & WHATWG ), semantics as it applies to HTML5 layout is subjective. 尽管HTML5标签定义有两个版本( W3CWHATWG ),但是应用于HTML5布局的语义是主观的。 Your page will function just as well with <div> and <span> (case in point: Bootstrap.) 您的页面也可以与<div><span> (例如:Bootstrap。)

<article> over <blockquote> <article> over <blockquote>

Article can stand on its own and carries the flow of a topic which can be divided into sub-topics by <section> and therein would be text and media content grouped in <p> , <figure> , etc. 文章可以独立存在并带有一个主题的流程,可以通过<section>划分为子主题,其中的文本和媒体内容分为<p><figure>等。

To wrap up all the content in a neat package is <main> and the peripherals would be the <header> and <footer> which usually hold content that is common to most of the pages like <nav> or <address> , support links, etc. 将整个软件包中的所有内容包装起来是<main> ,外围设备将是<header><footer> ,它们通常包含大多数页面所共有的内容,如<nav><address> ,支持链接等

A <blockquote> is an extended reiteration of a work (ex. book, poem, speech, etc). <blockquote>是作品的延伸重复(例如书,诗,演讲等)。 So it isn't suitable for a comment. 所以它不适合评论。

As for listing each comment, I'd skip that because an <article> stands on its own. 至于列出每个评论,我会跳过它,因为<article>独立。

Without all the gory details I submit to you my take on a semantic layout: 如果没有我提交给你的所有血腥细节我对语义布局的看法:

Demo 演示

 <header> <nav></nav> </header> <main id='page11'> <article class="comment"> <figure class="avatar"> <img ...> <figcaption class="author">Linus Torvalds</figcaption> </figure> <section class='content'> <p class="comment-text"> Linux is awesome! </p> </section> </article> </main> <footer> <address></address> </footer> 

Each comment should be an article ( no matter if you'll use a list or not). 每条评论都应该是一篇article无论您是否使用列表)。 These article elements could be part of a section ( representing the comment area ), and this section should be part of the article the comments are for (eg, the blog post). 这些article的元素可能是部分section代表评论区 ),这section应该是部分article的评论是(例如,博客文章)。

<article>
  <h2>My blog post</h2>
  <section>
    <h3>Comments</h3>
    <article id="comment-1"></article>
    <article id="comment-2"></article>
    <article id="comment-3"></article>
  </section>
</article>

If you allow replying to comments and display them nested, the replies should be part of the parent comment: 如果您允许回复评论并将其显示为嵌套,则回复应该是父评论的一部分:

<article>
  <h2>My blog post</h2>
  <section>
    <h3>Comments</h3>
    <article id="comment-1"></article>
    <article id="comment-2">
      <article id="comment-2-1"></article>
      <article id="comment-2-2"></article>
      <article id="comment-2-3"></article>
    </article>
    <article id="comment-3"></article>
  </section>
</article>

Semantically, there is no need for a list here. 从语义上讲,这里不需要列表。 Thanks to using sectioning content elements ( section , article ), the comment section and each comment are part of the document outline, which can allow quick on-page navigation. 由于使用了分区内容元素( sectionarticle ),评论部分和每个评论都是文档大纲的一部分,这可以允许快速的页面导航。
Adding a list wouldn't be wrong, though, but I would recommend against it in this context (following my two rule of thumbs ) 但是,添加一个列表并没有错,但我建议在这种情况下反对它(遵循我的两个经验法则

Using blockquote for comments wouldn't be appropriate. 使用blockquote进行注释是不合适的。 This is their canonical/original location, you are not quoting from somewhere else. 他们的规范/原始位置,您不会从其他地方引用。 Thanks to using article , you already semantically convey that the content inside could be from another author than the content outside of it (because article allows you to "scope" the address element and the author link type ). 感谢您使用article ,您已经在语义上传达了内部内容可能来自其他作者而非其外部内容(因为article允许您“范围” address元素和author链接类型 )。

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

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