导航

v2.1.0
内容

讨论串

每条回复都用连线指向它所回复的评论。

本页内容

讨论串由评论及其回复组成,常见于文档、评审或议题下方。每条评论的 头像 位于一列,正文排在旁边。回复排在正文下方,一条细线从评论头像向下延伸,再转向每条回复。读者顺着连线就能看出每条回复对应哪条评论,无需根据缩进判断。

讨论串

<div class="card max-w(480) mx-auto">  <ol class="thread">    <li class="thread-item">      <span class="thread-avatar"><span class="avatar">AL</span></span>      <div class="thread-body">        <p class="thread-header">          <span class="thread-author">Ada Lovelace</span>          <time class="thread-meta" datetime="2026-11-12T09:12Z">2h</time>        </p>        <p class="thread-text">The focus ring is cut by the mask. Should it move to the group?</p>      </div>      <ol class="thread-replies">        <li class="thread-item">          <span class="thread-avatar"><span class="avatar avatar-sm">AT</span></span>          <div class="thread-body">            <p class="thread-header">              <span class="thread-author">Alan Turing</span>              <time class="thread-meta" datetime="2026-11-12T10:05Z">1h</time>            </p>            <p class="thread-text">              Yes. The group already has the corner, so the ring follows it.            </p>          </div>        </li>        <li class="thread-item">          <span class="thread-avatar"><span class="avatar avatar-sm">GH</span></span>          <div class="thread-body">            <p class="thread-header">              <span class="thread-author">Grace Hopper</span>              <time class="thread-meta" datetime="2026-11-12T10:31Z">35m</time>            </p>            <p class="thread-text">I will make the change this afternoon.</p>          </div>        </li>      </ol>    </li>    <li class="thread-item">      <span class="thread-avatar"><span class="avatar">KJ</span></span>      <div class="thread-body">        <p class="thread-header">          <span class="thread-author">Katherine Johnson</span>          <time class="thread-meta" datetime="2026-11-12T10:54Z">12m</time>        </p>        <p class="thread-text">The figures in the second table are right.</p>      </div>    </li>  </ol></div>
<div className="card max-w(480) mx-auto">  <ol className="thread">    <li className="thread-item">      <span className="thread-avatar"><span className="avatar">AL</span></span>      <div className="thread-body">        <p className="thread-header">          <span className="thread-author">Ada Lovelace</span>          <time className="thread-meta" dateTime="2026-11-12T09:12Z">2h</time>        </p>        <p className="thread-text">          The focus ring is cut by the mask. Should it move to the group?        </p>      </div>      <ol className="thread-replies">        <li className="thread-item">          <span className="thread-avatar"><span className="avatar avatar-sm">AT</span></span>          <div className="thread-body">            <p className="thread-header">              <span className="thread-author">Alan Turing</span>              <time className="thread-meta" dateTime="2026-11-12T10:05Z">1h</time>            </p>            <p className="thread-text">              Yes. The group already has the corner, so the ring follows it.            </p>          </div>        </li>        <li className="thread-item">          <span className="thread-avatar"><span className="avatar avatar-sm">GH</span></span>          <div className="thread-body">            <p className="thread-header">              <span className="thread-author">Grace Hopper</span>              <time className="thread-meta" dateTime="2026-11-12T10:31Z">35m</time>            </p>            <p className="thread-text">I will make the change this afternoon.</p>          </div>        </li>      </ol>    </li>    <li className="thread-item">      <span className="thread-avatar"><span className="avatar">KJ</span></span>      <div className="thread-body">        <p className="thread-header">          <span className="thread-author">Katherine Johnson</span>          <time className="thread-meta" dateTime="2026-11-12T10:54Z">12m</time>        </p>        <p className="thread-text">The figures in the second table are right.</p>      </div>    </li>  </ol></div>
<div class="card max-w(480) mx-auto">  <ol class="thread">    <li class="thread-item">      <span class="thread-avatar"><span class="avatar">AL</span></span>      <div class="thread-body">        <p class="thread-header">          <span class="thread-author">Ada Lovelace</span>          <time class="thread-meta" datetime="2026-11-12T09:12Z">2h</time>        </p>        <p class="thread-text">The focus ring is cut by the mask. Should it move to the group?</p>      </div>      <ol class="thread-replies">        <li class="thread-item">          <span class="thread-avatar"><span class="avatar avatar-sm">AT</span></span>          <div class="thread-body">            <p class="thread-header">              <span class="thread-author">Alan Turing</span>              <time class="thread-meta" datetime="2026-11-12T10:05Z">1h</time>            </p>            <p class="thread-text">              Yes. The group already has the corner, so the ring follows it.            </p>          </div>        </li>        <li class="thread-item">          <span class="thread-avatar"><span class="avatar avatar-sm">GH</span></span>          <div class="thread-body">            <p class="thread-header">              <span class="thread-author">Grace Hopper</span>              <time class="thread-meta" datetime="2026-11-12T10:31Z">35m</time>            </p>            <p class="thread-text">I will make the change this afternoon.</p>          </div>        </li>      </ol>    </li>    <li class="thread-item">      <span class="thread-avatar"><span class="avatar">KJ</span></span>      <div class="thread-body">        <p class="thread-header">          <span class="thread-author">Katherine Johnson</span>          <time class="thread-meta" datetime="2026-11-12T10:54Z">12m</time>        </p>        <p class="thread-text">The figures in the second table are right.</p>      </div>    </li>  </ol></div>
<template>  <div class="card max-w(480) mx-auto">    <ol class="thread">      <li class="thread-item">        <span class="thread-avatar"><span class="avatar">AL</span></span>        <div class="thread-body">          <p class="thread-header">            <span class="thread-author">Ada Lovelace</span>            <time class="thread-meta" datetime="2026-11-12T09:12Z">2h</time>          </p>          <p class="thread-text">The focus ring is cut by the mask. Should it move to the group?</p>        </div>        <ol class="thread-replies">          <li class="thread-item">            <span class="thread-avatar"><span class="avatar avatar-sm">AT</span></span>            <div class="thread-body">              <p class="thread-header">                <span class="thread-author">Alan Turing</span>                <time class="thread-meta" datetime="2026-11-12T10:05Z">1h</time>              </p>              <p class="thread-text">                Yes. The group already has the corner, so the ring follows it.              </p>            </div>          </li>          <li class="thread-item">            <span class="thread-avatar"><span class="avatar avatar-sm">GH</span></span>            <div class="thread-body">              <p class="thread-header">                <span class="thread-author">Grace Hopper</span>                <time class="thread-meta" datetime="2026-11-12T10:31Z">35m</time>              </p>              <p class="thread-text">I will make the change this afternoon.</p>            </div>          </li>        </ol>      </li>      <li class="thread-item">        <span class="thread-avatar"><span class="avatar">KJ</span></span>        <div class="thread-body">          <p class="thread-header">            <span class="thread-author">Katherine Johnson</span>            <time class="thread-meta" datetime="2026-11-12T10:54Z">12m</time>          </p>          <p class="thread-text">The figures in the second table are right.</p>        </div>      </li>    </ol>  </div></template>

#结构

thread 是一个列表,每个 thread-item 是一条评论,依次包含以下三个子元素:

  1. thread-avatar 包裹头像,构成连线向下延伸的一列。
  2. thread-body 容纳正文内容:先放一个 thread-header,其中包含 thread-author,并在姓名旁放一个 thread-meta,然后为每段文字各放一个 thread-text。无论页面如何设置段落的外边距,标题行和正文段落的外边距都为零。后面还可以放其他内容,例如 引用 或一排视觉上不抢眼的按钮。
  3. 有回复时,thread-replies 包含回复当前评论的 thread-item 列表。

评论下方有回复时,连线会自动出现。每条回复通过一段折线接入连线,折线在头像前止住。连线各段互不重叠,因为线条的墨色是半透明的,两段叠加会使局部变深。

#嵌套

回复也可以有回复。在回复内放入一个 thread-replies,连线就会向内延伸一层。评论头像使用 头像 的默认尺寸 32px;回复头像无论嵌套多深,都使用 24px 的 avatar-sm。

嵌套两三层就够了。每多一层就占用 36px 的宽度,手机上的讨论串嵌套太深,正文就没有足够的空间。达到这个层级后,如需继续回复,就在回复开头写上被回复者的姓名,并将回复留在同一层。

嵌套

<div class="card max-w(480) mx-auto">  <ol class="thread">    <li class="thread-item">      <span class="thread-avatar"><span class="avatar">GH</span></span>      <div class="thread-body">        <p class="thread-header">          <span class="thread-author">Grace Hopper</span>          <time class="thread-meta" datetime="2026-11-12T08:02Z">3h</time>        </p>        <p class="thread-text">Can we ship the contracts before the framework components?</p>      </div>      <ol class="thread-replies">        <li class="thread-item">          <span class="thread-avatar"><span class="avatar avatar-sm">AL</span></span>          <div class="thread-body">            <p class="thread-header">              <span class="thread-author">Ada Lovelace</span>              <time class="thread-meta" datetime="2026-11-12T08:40Z">2h</time>            </p>            <p class="thread-text">Yes, they do not depend on each other.</p>          </div>          <ol class="thread-replies">            <li class="thread-item">              <span class="thread-avatar"><span class="avatar avatar-sm">GH</span></span>              <div class="thread-body">                <p class="thread-header">                  <span class="thread-author">Grace Hopper</span>                  <time class="thread-meta" datetime="2026-11-12T08:44Z">2h</time>                </p>                <p class="thread-text">Then Tuesday.</p>              </div>            </li>          </ol>        </li>      </ol>    </li>  </ol></div>
<div className="card max-w(480) mx-auto">  <ol className="thread">    <li className="thread-item">      <span className="thread-avatar"><span className="avatar">GH</span></span>      <div className="thread-body">        <p className="thread-header">          <span className="thread-author">Grace Hopper</span>          <time className="thread-meta" dateTime="2026-11-12T08:02Z">3h</time>        </p>        <p className="thread-text">Can we ship the contracts before the framework components?</p>      </div>      <ol className="thread-replies">        <li className="thread-item">          <span className="thread-avatar"><span className="avatar avatar-sm">AL</span></span>          <div className="thread-body">            <p className="thread-header">              <span className="thread-author">Ada Lovelace</span>              <time className="thread-meta" dateTime="2026-11-12T08:40Z">2h</time>            </p>            <p className="thread-text">Yes, they do not depend on each other.</p>          </div>          <ol className="thread-replies">            <li className="thread-item">              <span className="thread-avatar"><span className="avatar avatar-sm">GH</span></span>              <div className="thread-body">                <p className="thread-header">                  <span className="thread-author">Grace Hopper</span>                  <time className="thread-meta" dateTime="2026-11-12T08:44Z">2h</time>                </p>                <p className="thread-text">Then Tuesday.</p>              </div>            </li>          </ol>        </li>      </ol>    </li>  </ol></div>
<div class="card max-w(480) mx-auto">  <ol class="thread">    <li class="thread-item">      <span class="thread-avatar"><span class="avatar">GH</span></span>      <div class="thread-body">        <p class="thread-header">          <span class="thread-author">Grace Hopper</span>          <time class="thread-meta" datetime="2026-11-12T08:02Z">3h</time>        </p>        <p class="thread-text">Can we ship the contracts before the framework components?</p>      </div>      <ol class="thread-replies">        <li class="thread-item">          <span class="thread-avatar"><span class="avatar avatar-sm">AL</span></span>          <div class="thread-body">            <p class="thread-header">              <span class="thread-author">Ada Lovelace</span>              <time class="thread-meta" datetime="2026-11-12T08:40Z">2h</time>            </p>            <p class="thread-text">Yes, they do not depend on each other.</p>          </div>          <ol class="thread-replies">            <li class="thread-item">              <span class="thread-avatar"><span class="avatar avatar-sm">GH</span></span>              <div class="thread-body">                <p class="thread-header">                  <span class="thread-author">Grace Hopper</span>                  <time class="thread-meta" datetime="2026-11-12T08:44Z">2h</time>                </p>                <p class="thread-text">Then Tuesday.</p>              </div>            </li>          </ol>        </li>      </ol>    </li>  </ol></div>
<template>  <div class="card max-w(480) mx-auto">    <ol class="thread">      <li class="thread-item">        <span class="thread-avatar"><span class="avatar">GH</span></span>        <div class="thread-body">          <p class="thread-header">            <span class="thread-author">Grace Hopper</span>            <time class="thread-meta" datetime="2026-11-12T08:02Z">3h</time>          </p>          <p class="thread-text">Can we ship the contracts before the framework components?</p>        </div>        <ol class="thread-replies">          <li class="thread-item">            <span class="thread-avatar"><span class="avatar avatar-sm">AL</span></span>            <div class="thread-body">              <p class="thread-header">                <span class="thread-author">Ada Lovelace</span>                <time class="thread-meta" datetime="2026-11-12T08:40Z">2h</time>              </p>              <p class="thread-text">Yes, they do not depend on each other.</p>            </div>            <ol class="thread-replies">              <li class="thread-item">                <span class="thread-avatar"><span class="avatar avatar-sm">GH</span></span>                <div class="thread-body">                  <p class="thread-header">                    <span class="thread-author">Grace Hopper</span>                    <time class="thread-meta" datetime="2026-11-12T08:44Z">2h</time>                  </p>                  <p class="thread-text">Then Tuesday.</p>                </div>              </li>            </ol>          </li>        </ol>      </li>    </ol>  </div></template>

#讨论串还是消息

讨论串围绕一个主题展开,各条评论地位平等,都可以被回复。一条 消息 是双方对话中的一次发言,以指向发言者的气泡呈现。没有人回复的事件用 时间线 呈现。

#无障碍

  • 用 <ol> 编写讨论串,用嵌套的 <ol> 表示回复。嵌套结构表达回复关系,屏幕阅读器会读出层级和回复数量,对应视觉上由连线呈现的信息。
  • 每个时间都用带 datetime 的 <time> 标记,因为“2h”只是某个确切时间的简写。
  • 连线由样式表绘制,屏幕阅读器不会读出它。在强制颜色模式下,连线使用文本颜色。
  • 作者姓名旁显示姓名首字母或照片的头像仅作装饰,因为旁边已有姓名文本。

#类名

类名说明
thread评论列表,评论之间相隔 20px。
thread-item一条评论:头像独占一列,正文在旁边,回复在正文下方
thread-avatar包裹头像的列。有后续回复时,连线从头像下方开始。
thread-body正文区由 thread-header 和下方的 thread-text 组成,首行与头像的垂直中心对齐。
thread-header正文首行显示作者,时间放在姓名旁
thread-text标题区下方的正文,段落间距为 8px
thread-author以醒目的墨色显示作者姓名
thread-meta在作者姓名旁以较弱的视觉样式显示时间及其他信息。
thread-replies回复列表位于 thread-item 的正文之后。每条回复也是一个 thread-item,通过折线连接到评论。

#自定义属性

属性默认值说明
--thread-avatar2rem评论头像尺寸,回复头像使用 1.5rem
--thread-gap.75rem头像与配套文字的间距
--thread-space1.25rem评论间距,回复之间为 .875rem

#源码

@master/ui/components/thread.css
/* * Thread: comments and their replies, each joined to the comment it answers. * A comment is an avatar on a column and its words beside it. Replies stand under the words, and a hairline * runs down from the comment's avatar and turns into each of them: a reader follows a line, not an indent, * to see what answers what. The line is drawn in pieces that never overlap, since its ink is translucent: * the stretch under the avatar, an elbow into each reply, and the stretch on to the next one. * Geometry: a 32px avatar for a comment and 24px for a reply (avatar-sm), 12px between an avatar and its * words, 20px between comments and 14px between replies. The name stands level with the middle of its avatar. */@layer components.ui {  .thread {    --thread-avatar: 2rem;    --thread-gap: .75rem;    --thread-space: 1.25rem;    display: grid;    gap: var(--thread-space);    min-width: 0;    margin: 0;    padding: 0;    color: var(--color-text-body);    font-size: .875rem;    line-height: 1.55;    list-style: none;  }  /* One comment: the avatar's column, the words, and under the words its replies. */  .thread-item {    /* Where this comment's line runs, for the replies that turn off it. */    --thread-rail: calc(var(--thread-avatar) / 2);    position: relative;    display: grid;    grid-template-columns: var(--thread-avatar) minmax(0, 1fr);    column-gap: var(--thread-gap);    min-width: 0;  }  /* The avatar's column. Under the avatar the line begins, when replies follow. */  .thread-avatar {    display: flex;    grid-area: 1 / 1;    flex-direction: column;    align-items: center;    min-width: 0;    /* The avatar fills the column: a comment's is --thread-avatar, a reply's the size smaller. A size class on it still wins. */    .avatar {      --avatar-size: var(--thread-avatar);    }    &:has(~ .thread-replies)::after {      content: '';      flex: 1 1 0;      width: 1px;      margin-block-start: .25rem;      background: var(--color-line-divider);    }    @media (forced-colors: active) {      &:has(~ .thread-replies)::after {        background: CanvasText;      }    }  }  /* The words: a line that says who and when, then what they wrote. The first line is level with the middle of the avatar. */  .thread-body {    display: grid;    grid-area: 1 / 2;    gap: .125rem;    min-width: 0;    padding-block-start: calc((var(--thread-avatar) - 1.25rem) / 2);    overflow-wrap: anywhere;  }  /* The line with the name on it, and what is said quietly beside the name. */  .thread-header {    display: flex;    flex-wrap: wrap;    align-items: baseline;    gap: 0 .5rem;    min-width: 0;    margin: 0;  }  /* What they wrote. Several paragraphs stand 8px apart. */  .thread-text {    min-width: 0;    margin: 0;    text-wrap: pretty;    & + & {      margin-block-start: .375rem;    }  }  /* Who wrote it. */  .thread-author {    color: var(--color-text-strong);    font-weight: var(--font-weight-control);    line-height: 1.25rem;  }  /* When, and anything else said quietly beside the name. */  .thread-meta {    color: var(--color-text-muted);    font-size: .78125rem;    font-variant-numeric: tabular-nums;    line-height: 1.25rem;  }  /* The replies, under the words. Their avatars are a size smaller. */  .thread-replies {    --thread-parent: var(--thread-rail);    --thread-avatar: 1.5rem;    --thread-space: .875rem;    display: grid;    grid-area: 2 / 2;    min-width: 0;    margin: 0;    padding: 0;    list-style: none;    .thread-item {      padding-block-start: var(--thread-space);      /* The elbow: down the comment's line, then round into this reply's avatar, stopping 4px short of it. */      &::before {        content: '';        position: absolute;        inset-block-start: 0;        inset-inline-start: calc(-1 * (var(--thread-gap) + var(--thread-parent)) - .5px);        width: calc(var(--thread-gap) + var(--thread-parent) - .25rem);        height: calc(var(--thread-space) + var(--thread-avatar) / 2);        border-block-end: 1px solid var(--color-line-divider);        border-inline-start: 1px solid var(--color-line-divider);        border-end-start-radius: .625rem;        pointer-events: none;      }      /* The line goes on to the next reply, from where the elbow leaves it. */      &:not(:last-child)::after {        content: '';        position: absolute;        inset-block: calc(var(--thread-space) + var(--thread-avatar) / 2 - .625rem) 0;        inset-inline-start: calc(-1 * (var(--thread-gap) + var(--thread-parent)) - .5px);        width: 1px;        background: var(--color-line-divider);        pointer-events: none;      }      @media (forced-colors: active) {        &::before {          border-color: CanvasText;        }        &:not(:last-child)::after {          background: CanvasText;        }      }    }  }}