导航

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 的文章。在以前景色为底色的表面上,标记也会随文字一起切换颜色。

#项目列表、列表还是核对清单

项目列表的条目用句子来写。每行都有媒体内容、标题和末尾内容时,使用列表。供读者逐项勾选的待办事项使用核对清单。术语及其对应值使用数据列表。

#无障碍

  • 使用 <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;      }    }  }}