網站導覽

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> 標記,讓畫面上的「2 小時前」等簡短文字也有對應的確切時間。
  • 連線由樣式表繪製,螢幕閱讀器不會讀出。在強制色彩模式下,連線會使用文字色。
  • 作者名稱旁顯示姓名縮寫或照片的頭像屬於裝飾,旁邊的文字已提供作者名稱。

#類別

類別說明
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;        }      }    }  }}