accent-color

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

accent-color CSS 屬性為某些元素生成的使用者介面控制元件設定強調色。

試一試

accent-color: red;
accent-color: #74992e;
accent-color: rgb(255 255 128);
accent-color: hsl(250 100% 34%);
<section class="default-example container" id="default-example">
  <div>
    <input checked="" id="example-element" type="checkbox" />
    <label for="example-element" id="example-label">Example Label</label>
  </div>
</section>
.container > div {
  display: flex;
  align-items: center;
}

#example-element {
  width: 40px;
  height: 40px;
}

#example-label {
  margin-left: 10px;
  font-size: x-large;
}

目前支援 accent-color 的瀏覽器將其應用於以下 HTML 元素

每個使用者代理都有一個強調色,並帶有變化以確保易讀性和對比度。該強調色並非用於每個使用者介面控制元件,也並非用於控制元件的每種狀態。accent-color 僅適用於在其適用狀態下使用強調色的使用者介面控制元件。

語法

css
/* Keyword values */
accent-color: auto;

/* <color> values */
accent-color: darkred;
accent-color: #5729e9;
accent-color: rgb(0 200 0);
accent-color: hsl(228 4% 24%);

/* Global values */
accent-color: inherit;
accent-color: initial;
accent-color: revert;
accent-color: revert-layer;
accent-color: unset;

auto

表示由使用者代理選擇的顏色,如果平臺有強調色,則應與平臺強調色匹配。

<color>

指定用作強調色的顏色。

正式定義

初始值auto
應用於所有元素
繼承性
計算值auto 按指定計算,<color> 值按 color 屬性的定義計算。
動畫型別按計算值型別

正式語法

accent-color = 
auto |
<color>

示例

設定自定義強調色

HTML

html
<input type="checkbox" checked />
<input type="checkbox" class="custom" checked />

CSS

css
input {
  accent-color: auto;
  display: block;
  width: 30px;
  height: 30px;
}

input.custom {
  accent-color: rebeccapurple;
}

結果

規範

規範
CSS Basic User Interface Module Level 4
# widget-accent

瀏覽器相容性

另見