导航

v2.1.0
材质

分隔线

区段之间的细分隔线,可附标签。

本页内容

分隔线是一条隔开各个区段的细线。将 .divider 用在自带分隔符角色的 <hr> 上。线条的分隔效果最强,只有靠间距和分组仍不足以区分内容时才使用。

分隔线

<p class="m(0) text-sm fg-text-body">Billing is managed by the workspace owner.</p><hr class="divider"><p class="m(0) text-sm fg-text-body">Invoices are sent on the first day of each month.</p>
<>  <p className="m(0) text-sm fg-text-body">Billing is managed by the workspace owner.</p>  <hr className="divider" />  <p className="m(0) text-sm fg-text-body">Invoices are sent on the first day of each month.</p></>
<p class="m(0) text-sm fg-text-body">Billing is managed by the workspace owner.</p><hr class="divider"><p class="m(0) text-sm fg-text-body">Invoices are sent on the first day of each month.</p>
<template>  <p class="m(0) text-sm fg-text-body">Billing is managed by the workspace owner.</p>  <hr class="divider">  <p class="m(0) text-sm fg-text-body">Invoices are sent on the first day of each month.</p></template>

#带标签

divider-label 将分隔线分成两段,分列说明文字两侧。将它用在带有 role="separator" 的元素上,因为 <hr> 无法容纳文本。

带标签

<button type="button" class="btn w-full">Continue with a passkey</button><div class="divider divider-label" role="separator">or</div><input class="input" type="email" placeholder="you@example.com" aria-label="Email">
<>  <button type="button" className="btn w-full">Continue with a passkey</button>  <div className="divider divider-label" role="separator">or</div>  <input className="input" type="email" placeholder="you@example.com" aria-label="Email" /></>
<button type="button" class="btn w-full">Continue with a passkey</button><div class="divider divider-label" role="separator">or</div><input class="input" type="email" placeholder="you@example.com" aria-label="Email">
<template>  <button type="button" class="btn w-full">Continue with a passkey</button>  <div class="divider divider-label" role="separator">or</div>  <input class="input" type="email" placeholder="you@example.com" aria-label="Email"></template>

#垂直分隔线

divider-vertical 将同一行中的项目隔开,高度与该行一致。用于分隔多组控件时,添加 role="separator" 和 aria-orientation="vertical"。仅用于视觉分隔时,用 aria-hidden="true" 使辅助技术忽略它。

垂直分隔线

<div class="flex items-center gap-sm">  <button type="button" class="btn btn-quiet btn-sm">Edit</button>  <span class="divider divider-vertical" role="separator" aria-orientation="vertical"></span>  <button type="button" class="btn btn-quiet btn-sm">Share</button>  <button type="button" class="btn btn-quiet btn-sm">Export</button></div>
<div className="flex items-center gap-sm">  <button type="button" className="btn btn-quiet btn-sm">Edit</button>  <span className="divider divider-vertical" role="separator" aria-orientation="vertical"></span>  <button type="button" className="btn btn-quiet btn-sm">Share</button>  <button type="button" className="btn btn-quiet btn-sm">Export</button></div>
<div class="flex items-center gap-sm">  <button type="button" class="btn btn-quiet btn-sm">Edit</button>  <span class="divider divider-vertical" role="separator" aria-orientation="vertical"></span>  <button type="button" class="btn btn-quiet btn-sm">Share</button>  <button type="button" class="btn btn-quiet btn-sm">Export</button></div>
<template>  <div class="flex items-center gap-sm">    <button type="button" class="btn btn-quiet btn-sm">Edit</button>    <span class="divider divider-vertical" role="separator" aria-orientation="vertical"></span>    <button type="button" class="btn btn-quiet btn-sm">Share</button>    <button type="button" class="btn btn-quiet btn-sm">Export</button>  </div></template>

#类名

类名说明
divider一条 1px 的分隔线,颜色为 --color-line-divider
divider-vertical同一行内条目之间的分隔线,与该行等高与 divider 一同使用
divider-label分隔线在“或”等文字两侧断开。hr 无法容纳文字,请将类用于带 role="separator" 的元素。与 divider 一同使用

#源码

@master/ui/components/divider.css
/* * Divider: one hairline between sections, on an <hr> or an element with role="separator". * With a label, the line parts around the words. */@layer components.ui {  .divider {    flex: none;    height: 1px;    margin: 0;    border: 0;    background: var(--color-line-divider);    color: var(--color-text-muted);    /* Between items in a row: it takes the row's height. */    &.divider-vertical {      align-self: stretch;      width: 1px;      height: auto;      min-height: 1em;    }    /* A caption in the line, such as "or". */    &.divider-label {      display: flex;      align-items: center;      gap: .75rem;      height: auto;      background: none;      font-size: .75rem;      line-height: 1.5;      /* A caption longer than its room wraps in the middle and leaves a line on each side, so it still parts. */      text-align: center;      text-wrap: balance;      &::before, &::after {        content: '';        flex: 1 0 1.5rem;        height: 1px;        background: var(--color-line-divider);      }    }    @media (forced-colors: active) {      background: CanvasText;      &.divider-label {        background: none;        &::before, &::after {          background: CanvasText;        }      }    }  }}