导航

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;      }    }  }}