網站導覽

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 將線條分成兩段,在中間留出文字的位置。由於 <hr> 無法容納文字,請將它用在具有 role="separator" 的元素上。

加上標籤

<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使用 --color-line-divider 的 1px 分隔線
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;        }      }    }  }}