網站導覽

v2.1.0
文字排版

引註

句子中指向資料來源的小型編號標記。

本頁內容

引註是放在論述末尾的小型編號標記,指向該論述的來源。連結採用膠囊標籤的底色與圓弧外形,比正文稍小,也略高於基線。指標移到標記上或來源正在顯示時,標記的底色會變成墨色。

引註

<div class="max-w(480) mx-auto text-sm fg-text-body leading-md">  <p class="m(0)">    Corners are drawn as squircles where the browser has <code class="code">corner-shape</code><button type="button" class="citation" popovertarget="source-1" aria-label="Source 1">1</button><span class="popover" id="source-1" popover>      <span class="flex flex-col gap-xs">        <span class="fg-text-strong font-medium">          CSS Borders and Box Decorations Module Level 4        </span><span class="fg-text-muted text-xs">W3C Working Draft · w3.org</span>      </span>    </span> and as circles elsewhere, with the radius scaled so both look equally round.<a class="citation" href="#ref-2" aria-label="Source 2">2</a><a class="citation" href="#ref-3" aria-label="Source 3">3</a>  </p>  <ol class="mt-md pl-md text-xs fg-text-muted">    <li>CSS Borders and Box Decorations Module Level 4</li>    <li id="ref-2">Master UI theme guide, “Continuous corners”</li>    <li id="ref-3">Figma, “Desperately seeking squircles”</li>  </ol></div>
<div className="max-w(480) mx-auto text-sm fg-text-body leading-md">  <p className="m(0)">    Corners are drawn as squircles where the browser has <code className="code">corner-shape</code><button type="button" className="citation" popoverTarget="source-1" aria-label="Source 1">      1    </button><span className="popover" id="source-1" popover="">      <span className="flex flex-col gap-xs">        <span className="fg-text-strong font-medium">          CSS Borders and Box Decorations Module Level 4        </span><span className="fg-text-muted text-xs">W3C Working Draft · w3.org</span>      </span>    </span> and as circles elsewhere, with the radius scaled so both look equally round.<a className="citation" href="#ref-2" aria-label="Source 2">2</a><a className="citation" href="#ref-3" aria-label="Source 3">3</a>  </p>  <ol className="mt-md pl-md text-xs fg-text-muted">    <li>CSS Borders and Box Decorations Module Level 4</li>    <li id="ref-2">Master UI theme guide, “Continuous corners”</li>    <li id="ref-3">Figma, “Desperately seeking squircles”</li>  </ol></div>
<div class="max-w(480) mx-auto text-sm fg-text-body leading-md">  <p class="m(0)">    Corners are drawn as squircles where the browser has <code class="code">corner-shape</code><button type="button" class="citation" popovertarget="source-1" aria-label="Source 1">1</button><span class="popover" id="source-1" popover>      <span class="flex flex-col gap-xs">        <span class="fg-text-strong font-medium">          CSS Borders and Box Decorations Module Level 4        </span><span class="fg-text-muted text-xs">W3C Working Draft · w3.org</span>      </span>    </span> and as circles elsewhere, with the radius scaled so both look equally round.<a class="citation" href="#ref-2" aria-label="Source 2">2</a><a class="citation" href="#ref-3" aria-label="Source 3">3</a>  </p>  <ol class="mt-md pl-md text-xs fg-text-muted">    <li>CSS Borders and Box Decorations Module Level 4</li>    <li id="ref-2">Master UI theme guide, “Continuous corners”</li>    <li id="ref-3">Figma, “Desperately seeking squircles”</li>  </ol></div>
<template>  <div class="max-w(480) mx-auto text-sm fg-text-body leading-md">    <p class="m(0)">      Corners are drawn as squircles where the browser has <code class="code">corner-shape</code><button type="button" class="citation" popovertarget="source-1" aria-label="Source 1">        1      </button><span class="popover" id="source-1" popover>        <span class="flex flex-col gap-xs">          <span class="fg-text-strong font-medium">            CSS Borders and Box Decorations Module Level 4          </span><span class="fg-text-muted text-xs">W3C Working Draft · w3.org</span>        </span>      </span> and as circles elsewhere, with the radius scaled so both look equally round.<a class="citation" href="#ref-2" aria-label="Source 2">2</a><a class="citation" href="#ref-3" aria-label="Source 3">3</a>    </p>    <ol class="mt-md pl-md text-xs fg-text-muted">      <li>CSS Borders and Box Decorations Module Level 4</li>      <li id="ref-2">Master UI theme guide, “Continuous corners”</li>      <li id="ref-3">Figma, “Desperately seeking squircles”</li>    </ol>  </div></template>
第一個標記會在彈出面板中顯示來源,其餘標記會跳到來源清單。

#引註指向的位置

引註可指向下列兩個位置,兩種做法都無須腳本。

  • 來源清單通常放在回答或文章末尾。標記是 <a>,其 href 指向來源條目的 ID。
  • 彈出面板 會顯示來源標題及出處。引註標記是帶有 popovertarget 的 <button>,彈出面板須緊接在按鈕之後。面板開啟時,引註標記會維持填色。在段落內請用 <span> 作為彈出面板,因為段落不能包含 <div>。

標記前面請省略空格。它是行內元素,換行時會跟著前面的字詞,避免單獨出現在行首。

#無障礙

  • 單獨的數字無法說明標記的用途。請為每個標記加上 aria-label,例如「來源 2」,也可以直接使用來源標題。
  • 讓讀者無須操作引註標記也能查看來源。可快速瀏覽的來源清單比逐一開啟十幾個彈出面板方便。
  • 標記雖小,仍以控制項的字重顯示等寬數字,點按範圍也會隨所在文字的大小增加。

#類別

類別說明
citation標記可使用 href 指向來源 id 的 <a>,或使用帶有 popovertarget 的 <button>,並將按鈕緊接在對應的 popover 前面。請加上 aria-label,例如「來源 2」。

#原始碼

@master/ui/components/citation.css
/* * Citation: a small numbered mark in a sentence that points at where the sentence came from. * It is a link: a chip-toned pill a little smaller than the text and raised a little above its baseline, * with the number in tabular figures. It stays inline, so it wraps with the word it follows. Under the pointer, and while the source it opens is showing, it * fills with ink. The source itself is a popover or a list at the foot of the answer. */@layer components.ui {  .citation {    user-select: none;    -webkit-user-select: none;    /* Inline, not a box of its own: with no space before it, it never starts a line apart from its word. */    display: inline;    margin-inline: .2em .05em;    padding: .25em .5em;    border: 0;    border-radius: 999px;    corner-shape: round;    background: var(--citation-tone, var(--color-surface-chip));    color: var(--citation-ink, var(--color-text-body));    box-shadow: inset 0 0 0 .5px var(--citation-line, var(--color-line-contour));    font: var(--font-weight-control) .6875em/1 var(--font-family-sans);    font-feature-settings: inherit;    font-variant-numeric: tabular-nums;    letter-spacing: 0;    text-decoration: none;    white-space: nowrap;    vertical-align: .22em;    appearance: none;    cursor: pointer;    -webkit-tap-highlight-color: transparent;    /* It answers the pointer at once, as a row in a list does. */    @media (hover: hover) {      &:hover {        background: var(--citation-fill, var(--color-surface-inverse));        color: var(--citation-fill-ink, var(--color-text-inverse));        -webkit-text-fill-color: var(--citation-fill-text, currentColor);        box-shadow: none;      }    }    /* The mark under a press, the one whose source is open, or the one a reader has just followed. */    &:is(:active, [aria-expanded="true"], [aria-current="true"], :has(+ .popover:popover-open)) {      background: var(--citation-fill, var(--color-surface-inverse));      color: var(--citation-fill-ink, var(--color-text-inverse));      -webkit-text-fill-color: var(--citation-fill-text, currentColor);      box-shadow: none;    }    /* The theme's ring, at the offset a link's takes. */    &:focus-visible {      @apply --focus-ring;    }    @media (forced-colors: active) {      outline: 1px solid LinkText;      outline-offset: -1px;      color: LinkText;      /* The fill of an open or followed mark is gone with its colors: it takes the link color as its face. */      &:is([aria-expanded="true"], [aria-current="true"], :has(+ .popover:popover-open)) {        background: LinkText;        color: Canvas;        forced-color-adjust: none;      }      /* The words keep the system's colors, whatever face an ink surface would paint them in. */      &:is(:hover, :active, [aria-expanded="true"], [aria-current="true"], :has(+ .popover:popover-open)) {        -webkit-text-fill-color: currentColor;      }      /* A filled mark is kept out of forced colors, so its ring is given the system's color here. */      &:focus-visible {        outline: 2px solid Highlight;        outline-offset: 2px;      }    }  }}