網站導覽

v2.1.0
操作

連結

沿用句子的文字顏色,帶使用者前往其他位置。

本頁內容

連結帶使用者前往其他位置,並沿用所在句子的文字顏色。在單色介面中,連結以底線辨識。平時底線較淡,指標移上時會加深至文字的顏色。將 .link 加在 <a> 上。

連結

<p class="m(0) text-sm fg-text-body leading-md">  Master UI reads Master CSS tokens. Start with the <a class="link" href="#installation">installation guide</a>, then read how the <a class="link" href="#theme">theme</a> is built.</p>
<p className="m(0) text-sm fg-text-body leading-md">  Master UI reads Master CSS tokens. Start with the <a className="link" href="#installation">installation guide</a>, then read how the <a className="link" href="#theme">theme</a> is built.</p>
<p class="m(0) text-sm fg-text-body leading-md">  Master UI reads Master CSS tokens. Start with the <a class="link" href="#installation">installation guide</a>, then read how the <a class="link" href="#theme">theme</a> is built.</p>
<template>  <p class="m(0) text-sm fg-text-body leading-md">    Master UI reads Master CSS tokens. Start with the <a class="link" href="#installation">installation guide</a>, then read how the <a class="link" href="#theme">theme</a> is built.  </p></template>

#低調樣式

link-quiet 沿用周圍的文字顏色,互動時才顯示底線。適合用在頁尾、中繼資料或導覽清單,避免一整排連結讓頁面布滿底線。連結的位置或措辭仍須讓使用者看得出它是連結。

低調樣式

<nav class="flex gap-md text-sm fg-text-muted" aria-label="Footer">  <a class="link link-quiet" href="#docs">Docs</a>  <a class="link link-quiet" href="#changelog">Changelog</a>  <a class="link link-quiet" href="#license">License</a></nav>
<nav className="flex gap-md text-sm fg-text-muted" aria-label="Footer">  <a className="link link-quiet" href="#docs">Docs</a>  <a className="link link-quiet" href="#changelog">Changelog</a>  <a className="link link-quiet" href="#license">License</a></nav>
<nav class="flex gap-md text-sm fg-text-muted" aria-label="Footer">  <a class="link link-quiet" href="#docs">Docs</a>  <a class="link link-quiet" href="#changelog">Changelog</a>  <a class="link link-quiet" href="#license">License</a></nav>
<template>  <nav class="flex gap-md text-sm fg-text-muted" aria-label="Footer">    <a class="link link-quiet" href="#docs">Docs</a>    <a class="link link-quiet" href="#changelog">Changelog</a>    <a class="link link-quiet" href="#license">License</a>  </nav></template>

#新分頁

帶有 target="_blank" 的連結會顯示一個向外的小箭頭,提示使用者即將開啟新分頁。箭頭屬於裝飾,請在連結的無障礙名稱或可見文字中寫明「在新分頁開啟」,讓看不到箭頭的使用者也能得知。

新分頁

<p class="m(0) text-sm fg-text-body leading-md">  The corner shape follows the <a class="link" href="#spec" target="_blank" rel="noopener">    CSS Borders specification<span class="sr-only">(opens in a new tab)</span>  </a>.</p>
<p className="m(0) text-sm fg-text-body leading-md">  The corner shape follows the <a className="link" href="#spec" target="_blank" rel="noopener">    CSS Borders specification<span className="sr-only">(opens in a new tab)</span>  </a>.</p>
<p class="m(0) text-sm fg-text-body leading-md">  The corner shape follows the <a class="link" href="#spec" target="_blank" rel="noopener">    CSS Borders specification<span class="sr-only">(opens in a new tab)</span>  </a>.</p>
<template>  <p class="m(0) text-sm fg-text-body leading-md">    The corner shape follows the <a class="link" href="#spec" target="_blank" rel="noopener">      CSS Borders specification<span class="sr-only">(opens in a new tab)</span>    </a>.  </p></template>

連結用來導覽,按鈕用來執行動作。要讓導覽連結看起來像控制項,請在 <a> 上加上 btn。要在句子中提供「復原」之類的操作,請在 <button type="button"> 上加上 link,以保留按鈕的鍵盤操作方式與語意。

句子中的按鈕

<p class="m(0) text-sm fg-text-body">  The project was archived. <button type="button" class="link">Undo</button></p>
<p className="m(0) text-sm fg-text-body">  The project was archived. <button type="button" className="link">Undo</button></p>
<p class="m(0) text-sm fg-text-body">  The project was archived. <button type="button" class="link">Undo</button></p>
<template>  <p class="m(0) text-sm fg-text-body">    The project was archived. <button type="button" class="link">Undo</button>  </p></template>

#類別

類別說明
link帶底線的連結,使用醒目的文字色。指標移入時,底線會以與文字相同的顏色顯示
link-quiet沿用繼承的文字色,互動時才顯示底線,適合頁尾、中繼資料和導覽清單搭配 link 使用

#原始碼

@master/ui/components/link.css
/* * Link: text that goes somewhere, in the ink of its sentence. * The underline is a quiet line at rest and takes the full ink under the pointer, so links read without a hue. */@layer components.ui {  .link {    /* A button written as a link, for an action inside a sentence, drops the button's box. */    margin: 0;    padding: 0;    border: 0;    /* A small corner for the focus ring, from the chip's role and drawn as every other corner is. */    border-radius: calc((var(--radius-chip) - 4px) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: none;    font: inherit;    font-feature-settings: inherit;    appearance: none;    color: var(--color-text-strong);    text-decoration: underline;    text-decoration-color: var(--color-line-mark);    text-decoration-thickness: max(1px, .0625em);    text-underline-offset: .2em;    cursor: pointer;    -webkit-tap-highlight-color: transparent;    transition: text-decoration-color var(--duration-quick) var(--easing-glide), color var(--duration-quick) var(--easing-glide);    @media (hover: hover) {      &:hover {        text-decoration-color: currentColor;      }    }    /* Pressed: the full line, as under the pointer, so a tap is answered too. */    &:active {      text-decoration-color: currentColor;    }    &:focus-visible {      @apply --focus-ring;    }    /* A link that opens a new tab points out of the line it is in. Say "opens in a new tab" in its name too. */    &[target="_blank"]::after {      content: '';      display: inline-block;      width: .6875em;      height: .6875em;      margin-inline-start: .1875em;      background: currentColor;      opacity: .6;      mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10' fill='none' stroke='black' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 7.5 7.5 2.5M3.5 2.5h4v4'/%3E%3C/svg%3E") center / contain no-repeat;    }    /* From right to left the line runs the other way, and so does the arrow out of it. */    &[target="_blank"]:dir(rtl)::after {      scale: -1 1;    }    /* No line until touched, where a row of links would otherwise rule the page: footers, metadata, navigation. */    &.link-quiet {      color: inherit;      text-decoration-color: transparent;      @media (hover: hover) {        &:hover:not(:disabled, [aria-disabled="true"]) {          color: var(--color-text-strong);          text-decoration-color: var(--color-line-mark);        }      }      /* Pressed: the line shows here too, so a tap on a touch screen is answered. */      &:active:not(:disabled, [aria-disabled="true"]) {        color: var(--color-text-strong);        text-decoration-color: currentColor;      }    }    @media (forced-colors: active) {      color: LinkText;      text-decoration-color: currentColor;      /*       * The arrow is a fill under a mask, and forced colors would turn its fill to the canvas behind it: it keeps the       * link's own system color, at full strength.       */      &[target="_blank"]::after {        forced-color-adjust: none;        opacity: 1;      }    }  }  /* A link that cannot be followed now: no destination is promised, so it loses its ink and its line. */  .link:is(:disabled, [aria-disabled="true"]) {    color: var(--color-text-disabled);    text-decoration-color: transparent;    cursor: not-allowed;    @media (forced-colors: active) {      color: GrayText;    }  }}