导航

v2.1.0
数据展示

时间线

按时间顺序将事件排在一条线上,例如动态、历史记录或更新日志。

本页内容

时间线沿一条线按发生顺序排列事件,可用于活动动态、部署历史或变更日志。时间线是有序列表。每个事件的标记排在同一列,文字放在标记旁,一条细线将各个标记连起来。

时间线

<ol class="timeline max-w(360) mx-auto">  <li class="timeline-item" aria-current="true">    <span class="timeline-marker"></span>    <div class="timeline-body">      <p class="timeline-title">Deployed to production</p>      <p class="timeline-description">atlas.dev is live in 14 regions.</p>      <time class="timeline-time" datetime="2026-11-11T09:42Z">2 minutes ago</time>    </div>  </li>  <li class="timeline-item">    <span class="timeline-marker"></span>    <div class="timeline-body">      <p class="timeline-title">Build completed</p>      <p class="timeline-description">38 routes compiled in 48 seconds.</p>      <time class="timeline-time" datetime="2026-11-11T09:41Z">3 minutes ago</time>    </div>  </li>  <li class="timeline-item">    <span class="timeline-marker"></span>    <div class="timeline-body">      <p class="timeline-title">Commit pushed to main</p>      <time class="timeline-time" datetime="2026-11-11T09:40Z">4 minutes ago</time>    </div>  </li></ol>
<ol className="timeline max-w(360) mx-auto">  <li className="timeline-item" aria-current="true">    <span className="timeline-marker"></span>    <div className="timeline-body">      <p className="timeline-title">Deployed to production</p>      <p className="timeline-description">atlas.dev is live in 14 regions.</p>      <time className="timeline-time" dateTime="2026-11-11T09:42Z">2 minutes ago</time>    </div>  </li>  <li className="timeline-item">    <span className="timeline-marker"></span>    <div className="timeline-body">      <p className="timeline-title">Build completed</p>      <p className="timeline-description">38 routes compiled in 48 seconds.</p>      <time className="timeline-time" dateTime="2026-11-11T09:41Z">3 minutes ago</time>    </div>  </li>  <li className="timeline-item">    <span className="timeline-marker"></span>    <div className="timeline-body">      <p className="timeline-title">Commit pushed to main</p>      <time className="timeline-time" dateTime="2026-11-11T09:40Z">4 minutes ago</time>    </div>  </li></ol>
<ol class="timeline max-w(360) mx-auto">  <li class="timeline-item" aria-current="true">    <span class="timeline-marker"></span>    <div class="timeline-body">      <p class="timeline-title">Deployed to production</p>      <p class="timeline-description">atlas.dev is live in 14 regions.</p>      <time class="timeline-time" datetime="2026-11-11T09:42Z">2 minutes ago</time>    </div>  </li>  <li class="timeline-item">    <span class="timeline-marker"></span>    <div class="timeline-body">      <p class="timeline-title">Build completed</p>      <p class="timeline-description">38 routes compiled in 48 seconds.</p>      <time class="timeline-time" datetime="2026-11-11T09:41Z">3 minutes ago</time>    </div>  </li>  <li class="timeline-item">    <span class="timeline-marker"></span>    <div class="timeline-body">      <p class="timeline-title">Commit pushed to main</p>      <time class="timeline-time" datetime="2026-11-11T09:40Z">4 minutes ago</time>    </div>  </li></ol>
<template>  <ol class="timeline max-w(360) mx-auto">    <li class="timeline-item" aria-current="true">      <span class="timeline-marker"></span>      <div class="timeline-body">        <p class="timeline-title">Deployed to production</p>        <p class="timeline-description">atlas.dev is live in 14 regions.</p>        <time class="timeline-time" datetime="2026-11-11T09:42Z">2 minutes ago</time>      </div>    </li>    <li class="timeline-item">      <span class="timeline-marker"></span>      <div class="timeline-body">        <p class="timeline-title">Build completed</p>        <p class="timeline-description">38 routes compiled in 48 seconds.</p>        <time class="timeline-time" datetime="2026-11-11T09:41Z">3 minutes ago</time>      </div>    </li>    <li class="timeline-item">      <span class="timeline-marker"></span>      <div class="timeline-body">        <p class="timeline-title">Commit pushed to main</p>        <time class="timeline-time" datetime="2026-11-11T09:40Z">4 minutes ago</time>      </div>    </li>  </ol></template>

#标记

空的 timeline-marker 显示为小圆点。用 aria-current 标注最新事件或读者当前查看的事件,其标记会呈现墨色和淡淡的光晕。标记内放入 icon 时,图标周围会形成一个小凹槽。:has() 决定是否呈现这个凹槽,因此同一条时间线可以混用两种标记。

带图标

<ol class="timeline max-w(360) mx-auto">  <li class="timeline-item">    <span class="timeline-marker">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5" />      </svg>    </span>    <div class="timeline-body">      <p class="timeline-title">Ada approved the change</p>      <time class="timeline-time">Today at 09:12</time>    </div>  </li>  <li class="timeline-item">    <span class="timeline-marker">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M3.5 2.5L12.5 2.5A1 1 0 0 1 13.5 3.5L13.5 10A1 1 0 0 1 12.5 11L7.777 11A1 1 0 0 0 7.2625 11.1425L4.0145 13.0913A1 1 0 0 1 2.5 12.2338L2.5 3.5A1 1 0 0 1 3.5 2.5Z" />      </svg>    </span>    <div class="timeline-body">      <p class="timeline-title">Alan left a comment</p>      <p class="timeline-description">The focus ring is cut by the mask. Move it to the group.</p>      <time class="timeline-time">Yesterday at 17:40</time>    </div>  </li>  <li class="timeline-item">    <span class="timeline-marker"></span>    <div class="timeline-body">      <p class="timeline-title">Pull request opened</p>      <time class="timeline-time">Yesterday at 16:05</time>    </div>  </li></ol>
import CheckIcon from '@master/icons-react/native/16/soft/check'import MessageIcon from '@master/icons-react/native/16/soft/message'<ol className="timeline max-w(360) mx-auto">  <li className="timeline-item">    <span className="timeline-marker"><CheckIcon className="icon" /></span>    <div className="timeline-body">      <p className="timeline-title">Ada approved the change</p>      <time className="timeline-time">Today at 09:12</time>    </div>  </li>  <li className="timeline-item">    <span className="timeline-marker"><MessageIcon className="icon" /></span>    <div className="timeline-body">      <p className="timeline-title">Alan left a comment</p>      <p className="timeline-description">        The focus ring is cut by the mask. Move it to the group.      </p>      <time className="timeline-time">Yesterday at 17:40</time>    </div>  </li>  <li className="timeline-item">    <span className="timeline-marker"></span>    <div className="timeline-body">      <p className="timeline-title">Pull request opened</p>      <time className="timeline-time">Yesterday at 16:05</time>    </div>  </li></ol>
<script>  import CheckIcon from '@master/icons-svelte/native/16/soft/check'  import MessageIcon from '@master/icons-svelte/native/16/soft/message'</script><ol class="timeline max-w(360) mx-auto">  <li class="timeline-item">    <span class="timeline-marker"><CheckIcon class="icon" /></span>    <div class="timeline-body">      <p class="timeline-title">Ada approved the change</p>      <time class="timeline-time">Today at 09:12</time>    </div>  </li>  <li class="timeline-item">    <span class="timeline-marker"><MessageIcon class="icon" /></span>    <div class="timeline-body">      <p class="timeline-title">Alan left a comment</p>      <p class="timeline-description">The focus ring is cut by the mask. Move it to the group.</p>      <time class="timeline-time">Yesterday at 17:40</time>    </div>  </li>  <li class="timeline-item">    <span class="timeline-marker"></span>    <div class="timeline-body">      <p class="timeline-title">Pull request opened</p>      <time class="timeline-time">Yesterday at 16:05</time>    </div>  </li></ol>
<script setup>import CheckIcon from '@master/icons-vue/native/16/soft/check'import MessageIcon from '@master/icons-vue/native/16/soft/message'</script><template>  <ol class="timeline max-w(360) mx-auto">    <li class="timeline-item">      <span class="timeline-marker"><CheckIcon class="icon" /></span>      <div class="timeline-body">        <p class="timeline-title">Ada approved the change</p>        <time class="timeline-time">Today at 09:12</time>      </div>    </li>    <li class="timeline-item">      <span class="timeline-marker"><MessageIcon class="icon" /></span>      <div class="timeline-body">        <p class="timeline-title">Alan left a comment</p>        <p class="timeline-description">The focus ring is cut by the mask. Move it to the group.</p>        <time class="timeline-time">Yesterday at 17:40</time>      </div>    </li>    <li class="timeline-item">      <span class="timeline-marker"></span>      <div class="timeline-body">        <p class="timeline-title">Pull request opened</p>        <time class="timeline-time">Yesterday at 16:05</time>      </div>    </li>  </ol></template>

#时间线还是步骤

时间线的条目数量不固定,其中每个事件都已结束。步骤展示读者正在经历的固定流程,其中一步是当前步骤,其余步骤尚待进行。用执行轨迹展示正在进行的工作,其中的步骤可能正在运行或已经失败,也可以展开查看详情。

#无障碍

  • 顺序有意义时使用 <ol>,时间线几乎总是如此。每个时间点用带 datetime 的 <time> 表示。
  • 标记和连线由样式表绘制,辅助技术不会朗读它们。标记中的图标仅作装饰,请在标题里写明发生了什么。
  • 如果活动动态在显示期间会更新,请用 aria-live="polite" 将其设为实时区域。

#类名

类名说明
timeline列表
timeline-item表示一个事件,用细线将其标记与下一个标记相连。
timeline-marker无内容时显示为小圆点,有图标时显示为包裹图标的小凹槽。
timeline-body标记旁的文字。
timeline-title以高对比度墨色显示发生的事项
timeline-description强调程度较低的一行详情
timeline-time以等宽数字显示发生时间

#自定义属性

属性默认值说明
--timeline-marker1.5rem标记列的宽度

#源码

@master/ui/components/timeline.css
/* * Timeline: events in the order they happened, as a list on one line. * Each event has a marker on a column and its words beside it; a hairline joins the markers. A bare marker * is a small dot, and a marker that holds an icon becomes a small well around it. */@layer components.ui {  .timeline {    --timeline-marker: 1.5rem;    display: flex;    flex-direction: column;    min-width: 0;    margin: 0;    padding: 0;    color: var(--color-text-body);    font-size: .875rem;    line-height: 1.5;    list-style: none;  }  .timeline-item {    position: relative;    display: flex;    align-items: flex-start;    gap: .75rem;    min-width: 0;    padding-block-end: 1.25rem;    &:last-child {      padding-block-end: 0;    }    /*     * The line runs from under this marker to the next one, 2px clear of each. A marker sits centered on the     * first line, (1lh - --timeline-marker) / 2 from the item's top, so both ends are counted from there.     */    &:not(:last-child)::before {      content: '';      position: absolute;      inset-block: calc((1lh + var(--timeline-marker)) / 2 + .125rem) calc(.125rem - (1lh - var(--timeline-marker)) / 2);      inset-inline-start: calc(var(--timeline-marker) / 2 - .5px);      width: 1px;      background: var(--color-line-divider);    }    @media (forced-colors: active) {      &:not(:last-child)::before {        background: CanvasText;      }    }  }  /* The marker's column is as tall as the first line of text, so the dot sits on that line. */  .timeline-marker {    --icon-size: .875rem;    --icon-color: var(--color-text-muted);    display: grid;    flex: none;    place-items: center;    width: var(--timeline-marker);    height: var(--timeline-marker);    margin-block: calc((1lh - var(--timeline-marker)) / 2);    border-radius: 999px;    /* Bare: a dot. */    &:empty::before {      content: '';      width: .4375rem;      height: .4375rem;      border-radius: 999px;      background: var(--color-line-mark);    }    /* With an icon: a small well around it. */    &:has(.icon) {      background: var(--color-surface-inset);      box-shadow: var(--shadow-pressed);    }    @media (forced-colors: active) {      &:empty::before {        background: CanvasText;      }      &:has(.icon) {        outline: 1px solid CanvasText;        outline-offset: -1px;      }    }  }  /* The newest or current event: its dot takes ink. */  .timeline-item[aria-current]:not([aria-current="false"]) .timeline-marker:empty::before {    background: var(--color-text-strong);    box-shadow: 0 0 0 3px color-mix(in oklab, var(--color-text-strong) 12%, transparent);    /* A color that is not a system color would turn to Canvas here and the dot would vanish. */    @media (forced-colors: active) {      background: Highlight;    }  }  .timeline-body {    display: grid;    flex: 1 1 0;    gap: .125rem;    min-width: 0;  }  .timeline-title {    margin: 0;    color: var(--color-text-strong);    font-weight: var(--font-weight-control);    text-wrap: balance;    overflow-wrap: anywhere;  }  .timeline-description {    margin: 0;    color: var(--color-text-muted);    font-size: .8125rem;    text-wrap: pretty;    overflow-wrap: anywhere;  }  /* When it happened: a quiet line in tabular figures. */  .timeline-time {    margin: 0;    color: var(--color-text-muted);    font-size: .75rem;    font-variant-numeric: tabular-nums;  }}