::-webkit-meter-optimum-value
非標準:此特性未標準化。我們不建議在生產環境中使用非標準特性,因為它們瀏覽器支援有限,並且可能會更改或被移除。但是,在沒有標準選項的特定情況下,它們可以是合適的替代方案。
::-webkit-meter-optimum-value CSS 偽元素用於樣式化 <meter> 元素,當其值在低-高範圍內,或當其值等同於最佳值時。
綠色是預設顏色。
語法
css
::-webkit-meter-optimum-value {
/* ... */
}
示例
此示例僅適用於基於 WebKit 或 Blink 的瀏覽器。
HTML
html
Normal:
<meter min="0" max="10" low="3" high="7" optimum="6" value="6">
Score 6/10
</meter>
<br />
Styled:
<meter id="styled" min="0" max="10" low="3" high="7" optimum="6" value="6">
Score 6/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-optimum-value {
background: linear-gradient(
to bottom,
#77ff77,
#009900 45%,
#009900 55%,
#77ff77
);
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> 元素其他部分的偽元素如下: