::-webkit-meter-suboptimum-value

非標準:此特性未標準化。我們不建議在生產環境中使用非標準特性,因為它們瀏覽器支援有限,並且可能會更改或被移除。但是,在沒有標準選項的特定情況下,它們可以是合適的替代方案。

::-webkit-meter-suboptimum-value 偽元素 用於設定 <meter> 元素的樣式,當其 value 屬性的值超出低-高範圍且不等於最優值時。

預設顏色是黃色。

語法

css
::-webkit-meter-suboptimum-value {
  /* ... */
}

示例

此示例僅適用於基於 WebKit 或 Blink 的瀏覽器。

HTML

html
Normal:
<meter min="0" max="10" low="3" high="7" optimum="6" value="2">
  Score 2/10
</meter>
<br />
Styled:
<meter id="styled" min="0" max="10" low="3" high="7" optimum="6" value="2">
  Score 2/10
</meter>

CSS

css
body {
  font-family: monospace;
}

.safari meter {
  /* Reset the default appearance for Safari only */
  /* .safari class is added via JavaScript */
  -webkit-appearance: none;
}

#styled::-webkit-meter-suboptimum-value {
  background: linear-gradient(
    to bottom,
    #ffff77,
    #999900 45%,
    #999900 55%,
    #ffff77
  );
  height: 100%;
  box-sizing: border-box;
}

JavaScript

js
// Safari requires <meter> elements to have an `appearance` of `none` for custom styling
// using `::-webkit-meter-*` selectors, but `appearance: none` breaks rendering on Chrome.
// Therefore, we must check if the browser is Safari-based.

const is_safari =
  navigator.userAgent.includes("AppleWebKit/") &&
  !navigator.userAgent.includes("Chrome/");

if (is_safari) {
  document.body.classList.add("safari");
}

結果

規範

不屬於任何標準。

瀏覽器相容性

另見

WebKit/Blink 用於樣式化 <meter> 元素其他部分的偽元素如下: