網站導覽

v2.1.0
文字排版

醒目標記

像螢光筆一樣標出值得留意的文字。

本頁內容

醒目標記像螢光筆一樣,標出值得留意的文字,例如搜尋結果中相符的部分,或審閱者指出的詞句。它以低不透明度的文字色作為底色,讓標出的文字在各種背景上都清楚可讀,也不會干擾狀態色的辨識。請將 .mark 加在原生 <mark> 上。

醒目標記

<ul class="flex flex-col gap-xs m(0) p(0) text-sm fg-text-body">  <li class="flex"><span><mark class="mark">Moon</mark>stone palette</span></li>  <li class="flex"><span>Half-<mark class="mark">moon</mark> icon</span></li>  <li class="flex"><span>Phases of the <mark class="mark">moon</mark>, a field guide</span></li></ul>
<ul className="flex flex-col gap-xs m(0) p(0) text-sm fg-text-body">  <li className="flex"><span><mark className="mark">Moon</mark>stone palette</span></li>  <li className="flex"><span>Half-<mark className="mark">moon</mark> icon</span></li>  <li className="flex">    <span>Phases of the <mark className="mark">moon</mark>, a field guide</span>  </li></ul>
<ul class="flex flex-col gap-xs m(0) p(0) text-sm fg-text-body">  <li class="flex"><span><mark class="mark">Moon</mark>stone palette</span></li>  <li class="flex"><span>Half-<mark class="mark">moon</mark> icon</span></li>  <li class="flex"><span>Phases of the <mark class="mark">moon</mark>, a field guide</span></li></ul>
<template>  <ul class="flex flex-col gap-xs m(0) p(0) text-sm fg-text-body">    <li class="flex"><span><mark class="mark">Moon</mark>stone palette</span></li>    <li class="flex"><span>Half-<mark class="mark">moon</mark> icon</span></li>    <li class="flex"><span>Phases of the <mark class="mark">moon</mark>, a field guide</span></li>  </ul></template>

在清單方塊、組合方塊或指令面板中,隨使用者輸入,將各選項中相符的部分以醒目標記包住。

#目前的相符項目

讀者逐一瀏覽相符項目時,例如使用頁面內搜尋,請在目前所在的項目上設定 aria-current="true"。該項目的標記會以文字色填滿。

目前的相符項目

<p class="m(0) max-w(420) text-sm leading-md fg-text-body">  Corners nest by their <mark class="mark">inset</mark>: a container's radius is its content's radius plus the <mark class="mark" aria-current="true">inset</mark> between them, so the gap keeps one width around the bend. A button 4px inside a well takes the well's radius minus that <mark class="mark">inset</mark>.</p>
<p className="m(0) max-w(420) text-sm leading-md fg-text-body">  Corners nest by their <mark className="mark">inset</mark>: a container's radius is its content's radius plus the <mark className="mark" aria-current="true">inset</mark> between them, so the gap keeps one width around the bend. A button 4px inside a well takes the well's radius minus that <mark className="mark">inset</mark>.</p>
<p class="m(0) max-w(420) text-sm leading-md fg-text-body">  Corners nest by their <mark class="mark">inset</mark>: a container's radius is its content's radius plus the <mark class="mark" aria-current="true">inset</mark> between them, so the gap keeps one width around the bend. A button 4px inside a well takes the well's radius minus that <mark class="mark">inset</mark>.</p>
<template>  <p class="m(0) max-w(420) text-sm leading-md fg-text-body">    Corners nest by their <mark class="mark">inset</mark>: a container's radius is its content's radius plus the <mark class="mark" aria-current="true">inset</mark> between them, so the gap keeps one width around the bend. A button 4px inside a well takes the well's radius minus that <mark class="mark">inset</mark>.  </p></template>

#品牌色與底線

mark-brand 以淡淡的品牌色標出最能代表頁面主題的一段文字。mark-underline 則將標記畫在文字底部,形成一道粗底線。瀏覽器會在字形後方繪製底線,並在換行後繼續繪製。

品牌色與底線

<p class="m(0) max-w(420) text-md leading-md fg-text-strong">  Native HTML and CSS components with <mark class="mark mark-brand">no runtime</mark>, built on the platform and <mark class="mark mark-underline">finished by hand, one component at a time</mark>.</p>
<p className="m(0) max-w(420) text-md leading-md fg-text-strong">  Native HTML and CSS components with <mark className="mark mark-brand">no runtime</mark>, built on the platform and <mark className="mark mark-underline">finished by hand, one component at a time</mark>.</p>
<p class="m(0) max-w(420) text-md leading-md fg-text-strong">  Native HTML and CSS components with <mark class="mark mark-brand">no runtime</mark>, built on the platform and <mark class="mark mark-underline">finished by hand, one component at a time</mark>.</p>
<template>  <p class="m(0) max-w(420) text-md leading-md fg-text-strong">    Native HTML and CSS components with <mark class="mark mark-brand">no runtime</mark>, built on the platform and <mark class="mark mark-underline">finished by hand, one component at a time</mark>.  </p></template>

#無障礙

  • <mark> 表示「與此處的脈絡相關」。若要表達「重要」,請用 <strong>。多數螢幕閱讀器不會讀出醒目標記,因此還要有其他方式說明結果的意義。
  • 醒目標記保留原本的文字顏色,並以不透明度約 10% 的文字色襯底,因此對比維持不變。在強制色彩模式下,它使用系統的 Mark 和 MarkText。
  • 醒目標記跨行時,每一行都保有自己的內距和圓角。

#類別

類別說明
mark以周圍文字的顏色為基底,在文字後方加上淡色背景
mark-brand用淡淡的品牌色凸顯整頁的核心詞句。搭配 mark 使用
mark-underline用文字底部的粗線取代淡色底。搭配 mark 使用

#原始碼

@master/ui/components/mark.css
/* * Mark: a stroke of highlighter over the words that matter, such as the part of a result that matches * a search. It is a wash of ink, not a hue: it reads on every surface and never competes with status colors. * A holder of results may set --mark-ink and --mark-weight, as an option of a listbox does. * The match a reader has stepped to is filled with ink. The wash, the stroke and the fill are read through * --mark-tone, --mark-line, --mark-fill, --mark-fill-ink and --mark-fill-text, which a surface of ink sets with @apply --on-ink, * so a mark in a tooltip or a sent message is drawn from that surface's own text color. */@layer components.ui {  .mark {    margin-inline: -.125em;    padding: .0625em .125em;    border-radius: calc(.1875rem * var(--corner-scale));    corner-shape: var(--corner-shape);    background: var(--mark-tone, var(--color-mark));    /* A list of results sets --mark-ink and --mark-weight, so a match keeps the title's ink inside a muted line. */    color: var(--mark-ink, inherit);    font-weight: var(--mark-weight, inherit);    box-decoration-break: clone;    -webkit-box-decoration-break: clone;    /* Brand: a wash of the brand color, for the one phrase a page is about. */    &.mark-brand {      background: color-mix(in oklab, var(--color-brand) 18%, transparent);    }    /*     * The current match among several: set aria-current="true" on it as the reader steps through. It follows the     * brand wash, so a current brand match is filled with ink too and its inverse words stay legible.     */    &[aria-current="true"] {      background: var(--mark-fill, var(--color-surface-inverse));      color: var(--mark-fill-ink, var(--color-text-inverse));      -webkit-text-fill-color: var(--mark-fill-text, currentColor);    }    /*     * Underline: the stroke runs along the foot of the words instead of over them. It is a thick underline,     * which the browser paints behind the letters and carries across line breaks.     */    &.mark-underline {      margin-inline: 0;      padding: 0;      border-radius: 0;      background: none;      /* Longhands: the compiler orders declarations, and the shorthand would reset the thickness after it. */      text-decoration-line: underline;      text-decoration-thickness: .4em;      text-decoration-color: var(--mark-line, var(--color-mark-underline));      text-decoration-skip-ink: none;      text-underline-offset: -.18em;      /* The current match is filled with ink as any mark's is, and the stroke steps aside under it. */      &[aria-current="true"] {        /* The fill stands a little past the letters, as a wash's does, without moving them. */        margin-inline: -.125em;        padding: .0625em .125em;        border-radius: calc(.1875rem * var(--corner-scale));        background: var(--mark-fill, var(--color-surface-inverse));        text-decoration-color: transparent;      }    }    @media (forced-colors: active) {      background: Mark;      color: MarkText;      forced-color-adjust: none;      &.mark-brand {        background: Mark;      }      /* The stroke takes the mark's color, and the words over it keep the page's ink. */      &.mark-underline {        background: none;        color: CanvasText;        text-decoration-color: Mark;      }      &[aria-current="true"], &.mark-underline[aria-current="true"] {        background: Highlight;        color: HighlightText;        -webkit-text-fill-color: currentColor;        text-decoration-color: transparent;      }    }  }}