網站導覽

v2.1.0
文字排版

修訂

在原句中標示新增與刪除的文字。

本頁內容

修訂會在原句中標示新增與刪除的文字,可用來呈現建議的修改、追蹤修訂所記錄的變更,或更正。兩個類別各自套用在對應的原生元素上。將 ins 套用在 <ins> 上,會為新增文字加上淡色的成功狀態背景和細底線。將 del 套用在 <del> 上,會讓刪除文字的顏色稍淡,但仍維持文字所需的對比度,並加上淡色的危險狀態背景和刪除線。

修訂

<p class="m(0) max-w(480) mx-auto leading-md">  The release is planned for <del class="del">Thursday</del> <ins class="ins">Tuesday the 17th</ins>, and it <del class="del">will probably include</del> <ins class="ins">includes</ins> the new contracts. Every stylesheet has a contract beside it<ins class="ins">, and the two change together in the same commit</ins>.</p>
<p className="m(0) max-w(480) mx-auto leading-md">  The release is planned for <del className="del">Thursday</del> <ins className="ins">Tuesday the 17th</ins>, and it <del className="del">will probably include</del> <ins className="ins">includes</ins> the new contracts. Every stylesheet has a contract beside it<ins className="ins">, and the two change together in the same commit</ins>.</p>
<p class="m(0) max-w(480) mx-auto leading-md">  The release is planned for <del class="del">Thursday</del> <ins class="ins">Tuesday the 17th</ins>, and it <del class="del">will probably include</del> <ins class="ins">includes</ins> the new contracts. Every stylesheet has a contract beside it<ins class="ins">, and the two change together in the same commit</ins>.</p>
<template>  <p class="m(0) max-w(480) mx-auto leading-md">    The release is planned for <del class="del">Thursday</del> <ins class="ins">Tuesday the 17th</ins>, and it <del class="del">will probably include</del> <ins class="ins">includes</ins> the new contracts. Every stylesheet has a contract beside it<ins class="ins">, and the two change together in the same commit</ins>.  </p></template>

#兩種元素

修訂的語意由元素本身提供。<ins> 和 <del> 讓螢幕閱讀器、搜尋引擎以及未載入樣式表的瀏覽器都能辨識文字的變更。瀏覽器預設會分別以底線和刪除線呈現。兩種元素都可用 datetime 記錄修訂時間,並用 cite 指向說明這項修訂的文件。

類別會加上淡色底。和醒目標記一樣,修訂樣式可以跨行呈現。較長的新增文字換行時,每一行的兩端都會各自保有圓角。

#色彩與線條提示

新增與刪除是文字的兩種狀態,因此修訂會使用對應的兩種狀態色。狀態色須搭配其他提示。新增文字加上底線,刪除文字加上刪除線,讓無法辨識色彩的讀者仍能區分兩者。在強制色彩模式下,淡色底會移除,線條仍會保留。

卡片與墨色底上的效果

<div class="card w-full max-w(360)">  <p class="m(0)">    Ships on <del class="del">Thursday</del> <ins class="ins">Tuesday</ins>, with the contracts.  </p></div><div class="sheet sheet-inverse p(20) w-full max-w(360)">  <p class="m(0)">    Ships on <del class="del">Thursday</del> <ins class="ins">Tuesday</ins>, with the contracts.  </p></div>
<>  <div className="card w-full max-w(360)">    <p className="m(0)">      Ships on <del className="del">Thursday</del> <ins className="ins">Tuesday</ins>, with the contracts.    </p>  </div>  <div className="sheet sheet-inverse p(20) w-full max-w(360)">    <p className="m(0)">      Ships on <del className="del">Thursday</del> <ins className="ins">Tuesday</ins>, with the contracts.    </p>  </div></>
<div class="card w-full max-w(360)">  <p class="m(0)">    Ships on <del class="del">Thursday</del> <ins class="ins">Tuesday</ins>, with the contracts.  </p></div><div class="sheet sheet-inverse p(20) w-full max-w(360)">  <p class="m(0)">    Ships on <del class="del">Thursday</del> <ins class="ins">Tuesday</ins>, with the contracts.  </p></div>
<template>  <div class="card w-full max-w(360)">    <p class="m(0)">      Ships on <del class="del">Thursday</del> <ins class="ins">Tuesday</ins>, with the contracts.    </p>  </div>  <div class="sheet sheet-inverse p(20) w-full max-w(360)">    <p class="m(0)">      Ships on <del class="del">Thursday</del> <ins class="ins">Tuesday</ins>, with the contracts.    </p>  </div></template>

#修訂或程式碼

修訂用於句子中的文字變更。如果改動的是整行程式碼,請使用程式碼區塊,搭配 code-line-added 和 code-line-removed 標記該行及行旁的邊欄。若只是要強調原有文字,請用醒目標記。

#無障礙設計

  • 使用 <ins> 和 <del> 表達修訂的語意。檢查器會拒絕在 <span> 或其他元素上使用這些類別。
  • 各螢幕閱讀器預設是否會讀出新增與刪除有所不同。如果變更會影響理解,請在句中也說明,或在正文前摘要變更內容。
  • 替換文字時,先放刪除的文字,再放新增的文字,中間留一個空格,讀起來最順。

#類別

類別說明
ins在 ins 元素上以淡化的成功色作為背景,並以細底線標示新增文字。
deldel 元素中的刪除文字使用較淡但仍維持 4.5:1 文字對比的前景色,並搭配刪除線及淡化的危險色背景。

#原始碼

@master/ui/components/revision.css
/* * Revision: words added and words struck, inside the sentence they change. * On the native <ins> and <del>, which say what happened to anyone who cannot see it. Inserted words lie on * a wash of the success hue over a fine underline; deleted words take a quieter ink, on a wash of the * danger hue under a strike. The hue is a status here and never stands alone: the underline and the strike * say the same thing without it. Both carry across line breaks, like a stroke of highlighter. * For whole lines of code that changed, use a code block's added and removed lines. */@layer components.ui {  .ins, .del {    margin-inline: -.125em;    padding: .0625em .125em;    border-radius: calc(.1875rem * var(--corner-scale));    corner-shape: var(--corner-shape);    /* Longhands: the compiler orders declarations, and the shorthand would reset the thickness after it. */    text-decoration-thickness: 1px;    text-decoration-skip-ink: none;    box-decoration-break: clone;    -webkit-box-decoration-break: clone;  }  .ins {    background: color-mix(in oklab, var(--color-success) 13%, transparent);    color: inherit;    text-decoration-line: underline;    text-decoration-color: color-mix(in oklab, var(--color-success) 60%, transparent);    text-underline-offset: .22em;  }  /*   * A fifth of the ink is let go, no more: the struck words are still read, and at 80% body text keeps 4.5:1 on a   * page and on a raised sheet in both themes. Half the ink fell under 3:1.   */  .del {    background: color-mix(in oklab, var(--color-danger) 10%, transparent);    color: color-mix(in oklab, currentColor 80%, transparent);    text-decoration-line: line-through;    text-decoration-color: color-mix(in oklab, var(--color-danger) 75%, transparent);  }  /* After the washes and the lines above, so it is not overruled by them. */  @media (forced-colors: active) {    .ins, .del {      background: none;      text-decoration-color: CanvasText;    }  }}