網站導覽

v2.1.0
文字排版

條列清單

用於正文的清單,項目標記獨立成欄。

本頁內容

條列清單用在正文裡,例如文章中的重點、方案包含的項目,或以句子敘述的步驟。每個標記都排在獨立的欄位中,對齊該項目的第一行,因此文字換行時,所有項目的文字仍沿同一側對齊。清單使用原生的 <ul> 或 <ol>。

條列清單

<ul class="bullets max-w(420) mx-auto">  <li class="bullets-item">Every overlay is a native element, opened without script.</li>  <li class="bullets-item">    Tokens retune every component, and a theme is a file of them that selects no component.  </li>  <li class="bullets-item">Each stylesheet has a contract beside it that says what it promises.</li></ul>
<ul className="bullets max-w(420) mx-auto">  <li className="bullets-item">Every overlay is a native element, opened without script.</li>  <li className="bullets-item">    Tokens retune every component, and a theme is a file of them that selects no component.  </li>  <li className="bullets-item">    Each stylesheet has a contract beside it that says what it promises.  </li></ul>
<ul class="bullets max-w(420) mx-auto">  <li class="bullets-item">Every overlay is a native element, opened without script.</li>  <li class="bullets-item">    Tokens retune every component, and a theme is a file of them that selects no component.  </li>  <li class="bullets-item">Each stylesheet has a contract beside it that says what it promises.</li></ul>
<template>  <ul class="bullets max-w(420) mx-auto">    <li class="bullets-item">Every overlay is a native element, opened without script.</li>    <li class="bullets-item">      Tokens retune every component, and a theme is a file of them that selects no component.    </li>    <li class="bullets-item">      Each stylesheet has a contract beside it that says what it promises.    </li>  </ul></template>

#項目標記

預設的項目標記是小圓點。可用以下兩種類別更換清單標記。

  • bullets-check 以文字色繪製勾號,用來標示包含的項目,例如方案功能或版本新增內容。
  • bullets-numbered 使用等寬數字,並將編號靠標記欄尾端對齊,讓項目從 9 到 10 時仍能整齊排列。適用於順序本身具有意義的 <ol>。

勾號與編號

<ul class="bullets bullets-check w(220)">  <li class="bullets-item">Unlimited projects</li>  <li class="bullets-item">Custom domains, with certificates issued and renewed for you</li>  <li class="bullets-item">Preview for every branch</li></ul><ol class="bullets bullets-numbered w(220)">  <li class="bullets-item">Install the package.</li>  <li class="bullets-item">Import the stylesheet after the preset.</li>  <li class="bullets-item">Write the markup.</li></ol>
<>  <ul className="bullets bullets-check w(220)">    <li className="bullets-item">Unlimited projects</li>    <li className="bullets-item">Custom domains, with certificates issued and renewed for you</li>    <li className="bullets-item">Preview for every branch</li>  </ul>  <ol className="bullets bullets-numbered w(220)">    <li className="bullets-item">Install the package.</li>    <li className="bullets-item">Import the stylesheet after the preset.</li>    <li className="bullets-item">Write the markup.</li>  </ol></>
<ul class="bullets bullets-check w(220)">  <li class="bullets-item">Unlimited projects</li>  <li class="bullets-item">Custom domains, with certificates issued and renewed for you</li>  <li class="bullets-item">Preview for every branch</li></ul><ol class="bullets bullets-numbered w(220)">  <li class="bullets-item">Install the package.</li>  <li class="bullets-item">Import the stylesheet after the preset.</li>  <li class="bullets-item">Write the markup.</li></ol>
<template>  <ul class="bullets bullets-check w(220)">    <li class="bullets-item">Unlimited projects</li>    <li class="bullets-item">Custom domains, with certificates issued and renewed for you</li>    <li class="bullets-item">Preview for every branch</li>  </ul>  <ol class="bullets bullets-numbered w(220)">    <li class="bullets-item">Install the package.</li>    <li class="bullets-item">Import the stylesheet after the preset.</li>    <li class="bullets-item">Write the markup.</li>  </ol></template>

#未包含的項目

列出方案包含的內容時,未包含的項目也是清單要交代的資訊。在項目上加上 bullets-off,會把標記換成短橫線,並降低文字的對比。短橫線與色調是視覺提示,因此請在項目開頭加上「未包含:」等文字,並像範例一樣在包住這段文字的 span 上加上工具類別 sr-only,將它從畫面上隱藏,讓看不到這些提示的讀者也能取得相同資訊。

未包含

<div class="card w-full max-w(300)">  <div class="card-header">    <h3 class="card-title">Starter</h3>    <p class="card-description">For one person and a few projects.</p>  </div>  <ul class="bullets bullets-check">    <li class="bullets-item">Three projects</li>    <li class="bullets-item">Custom domains</li>    <li class="bullets-item bullets-off">      <span class="sr-only">Not included:</span>Single sign-on    </li>    <li class="bullets-item bullets-off"><span class="sr-only">Not included:</span>Audit log</li>  </ul></div>
<div className="card w-full max-w(300)">  <div className="card-header">    <h3 className="card-title">Starter</h3>    <p className="card-description">For one person and a few projects.</p>  </div>  <ul className="bullets bullets-check">    <li className="bullets-item">Three projects</li>    <li className="bullets-item">Custom domains</li>    <li className="bullets-item bullets-off">      <span className="sr-only">Not included:</span>Single sign-on    </li>    <li className="bullets-item bullets-off">      <span className="sr-only">Not included:</span>Audit log    </li>  </ul></div>
<div class="card w-full max-w(300)">  <div class="card-header">    <h3 class="card-title">Starter</h3>    <p class="card-description">For one person and a few projects.</p>  </div>  <ul class="bullets bullets-check">    <li class="bullets-item">Three projects</li>    <li class="bullets-item">Custom domains</li>    <li class="bullets-item bullets-off">      <span class="sr-only">Not included:</span>Single sign-on    </li>    <li class="bullets-item bullets-off"><span class="sr-only">Not included:</span>Audit log</li>  </ul></div>
<template>  <div class="card w-full max-w(300)">    <div class="card-header">      <h3 class="card-title">Starter</h3>      <p class="card-description">For one person and a few projects.</p>    </div>    <ul class="bullets bullets-check">      <li class="bullets-item">Three projects</li>      <li class="bullets-item">Custom domains</li>      <li class="bullets-item bullets-off">        <span class="sr-only">Not included:</span>Single sign-on      </li>      <li class="bullets-item bullets-off"><span class="sr-only">Not included:</span>Audit log</li>    </ul>  </div></template>

#巢狀清單與間距

項目內的 bullets 清單會縮排至該項目文字的起始邊緣,並與上方文字相隔 8px。項目間距預設為 8px,由 --bullets-gap 設定,標記欄寬度則由 --bullets-marker 設定。清單沿用周圍文字的字級、行高與文字色,標記對齊各項目的第一行。因此同一種清單可以用在字級為 14px 的卡片或 17px 的文章中,使用 ink 背景時,標記的顏色也會隨文字色調整。

#條列清單、清單與檢查清單

條列清單適合用句子列出重點。每列都有媒體、標題和尾端內容的項目,適合用清單。需要讀者逐項勾選的待辦事項,適合用檢查清單。成對呈現名稱與對應值時,請用資料清單。

#無障礙

  • 使用 <ul>,順序有意義時則使用 <ol>,每個項目用一個 <li> 標記。螢幕閱讀器會朗讀清單及其項目數量。樣式表繪製的標記不會被朗讀。
  • 清單的原生標記移除後,Safari 搭配 VoiceOver 時,只有加上 role="list" 才會將它讀成清單。如果項目數量有助於理解內容,請加上這個屬性。
  • 勾號和短橫線分別在視覺上表示「已包含」和「未包含」。請為未包含的項目加上文字說明。

#類別

類別說明
bullets項目之間相隔 8px,每個項目的小圓點位於 16px 寬的標記欄,標記欄與文字相隔 10px。清單沿用所在位置的文字色,在卡片和深色背景上都清楚可讀。
bullets-check已包含的項目會以文字色的勾號取代圓點搭配 bullets 使用
bullets-numbered各項編號使用等寬數字,對齊標記欄末端。用於 ol。搭配 bullets 使用
bullets-item單一項目。標記與第一行對齊,文字與其他項目的文字起始側對齊。
bullets-off未包含的項目以短橫線取代原有標記,文字也改用較低調的顏色搭配 bullets-item 使用

#自訂屬性

屬性預設值說明
--bullets-marker1rem標記欄寬度
--bullets-gap.5rem項目之間的間距

#原始碼

@master/ui/components/bullets.css
/* * Bullets: a list in running text, with its markers hung in a column of their own. * The list and its markers take the ink of the text they stand in, so it reads on a page, a card and an ink * surface alike. A marker is a small dot; with bullets-check it is a check, for what is included; with * bullets-numbered each item counts itself in tabular figures. The marker stands on the first line of its * item, however the text wraps, and the text of every item starts on one edge. * An item that is bullets-off is what is not included: a short dash in place of its marker and quieter words. * Say so in words as well, for a reader who sees neither. * Geometry: a 16px marker column, 10px from the text, and 8px between items. */@layer components.ui {  .bullets {    --bullets-marker: 1rem;    --bullets-gap: .5rem;    display: grid;    gap: var(--bullets-gap);    min-width: 0;    margin: 0;    padding: 0;    list-style: none;    counter-reset: bullets;    /* A list inside an item stands a little apart from the words over it. */    & & {      margin-block-start: var(--bullets-gap);    }    /* Included: a check. */    &.bullets-check .bullets-item::before {      width: .875rem;      height: .875rem;      margin-block: calc((1lh - .875rem) / 2);      border-radius: 0;      background: currentColor;      mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5'/%3E%3C/svg%3E") center / contain no-repeat;    }    /* Counted: the item's number, set to the end of the marker column so the figures line up on their points. */    &.bullets-numbered {      --bullets-marker: 1.25rem;      .bullets-item::before {        content: counter(bullets) '.';        width: var(--bullets-marker);        height: auto;        margin: 0;        border-radius: 0;        background: none;        /* Inside an item of a checked list the figures would be painted through the check's mask. */        mask: none;        /* Quieter than the words, and still 4.5:1 where the words are the body ink. */        color: color-mix(in oklab, currentColor 78%, transparent);        font-variant-numeric: tabular-nums;        text-align: end;      }    }    @media (forced-colors: active) {      &.bullets-check .bullets-item::before {        background: CanvasText;      }    }  }  /* One item: the marker in its column, the words beside it. */  .bullets-item {    position: relative;    min-width: 0;    margin: 0;    padding: 0;    padding-inline-start: calc(var(--bullets-marker) + .625rem);    text-wrap: pretty;    overflow-wrap: anywhere;    counter-increment: bullets;    /* The marker: a dot at the middle of the first line. */    &::before {      content: '';      position: absolute;      inset-block-start: 0;      inset-inline-start: calc((var(--bullets-marker) - .3125rem) / 2);      width: .3125rem;      height: .3125rem;      margin-block: calc((1lh - .3125rem) / 2);      border-radius: 999px;      background: color-mix(in oklab, currentColor 45%, transparent);    }    @media (forced-colors: active) {      &::before {        background: CanvasText;      }    }  }  .bullets-check .bullets-item::before, .bullets-numbered .bullets-item::before {    inset-inline-start: 0;  }  /*   * Not included: a dash where the marker was, and quieter words. They are still words to read: at 78% of the body   * ink they keep 4.5:1 on a raised face in both themes, where 62% fell to about 3.3:1.   */  .bullets .bullets-item.bullets-off {    color: color-mix(in oklab, currentColor 78%, transparent);    &::before {      content: '';      inset-inline-start: calc((var(--bullets-marker) - .5rem) / 2);      width: .5rem;      height: 1.5px;      margin-block: calc((1lh - 1.5px) / 2);      border-radius: 999px;      background: currentColor;      mask: none;    }    /* The dash's current color would be forced to the canvas and vanish: it takes the quiet system color. */    @media (forced-colors: active) {      &::before {        background: GrayText;      }    }  }}