:indeterminate

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

:indeterminate CSS 伪类表示任意的状态不确定的表单元素,例如那些将 HTML indeterminate 属性设置为 true 的复选框,以及属于某个组且该组中所有单选按钮都未选中的单选按钮,还有不确定状态的 <progress> 元素。

css
/* 选中任意的状态不确定的 <input> */
input:indeterminate {
  background: lime;
}

此选择器针对的元素是:

语法

:indeterminate

示例

复选框和单选按钮

这个示例将特殊样式应用于与不确定表单字段关联的标签。

HTML

html
<fieldset>
  <legend>Checkbox</legend>
  <div>
    <input type="checkbox" id="checkbox" />
    <label for="checkbox">This checkbox label starts out lime.</label>
  </div>
</fieldset>

<fieldset>
  <legend>Radio</legend>
  <div>
    <input type="radio" id="radio1" name="radioButton" value="val1" />
    <label for="radio1">First radio label starts out lime.</label>
  </div>
  <div>
    <input type="radio" id="radio2" name="radioButton" value="val2" />
    <label for="radio2">Second radio label also starts out lime.</label>
  </div>
</fieldset>

CSS

css
input:indeterminate + label {
  background: lime;
}

JavaScript

js
const inputs = document.getElementsByTagName("input");

for (let i = 0; i < inputs.length; i++) {
  inputs[i].indeterminate = true;
}

结果

进度条

HTML

html
<progress></progress>

CSS

css
progress {
  margin: 4px;
}

progress:indeterminate {
  width: 80vw;
  height: 20px;
}

结果

规范

Specification
HTML Standard
# selector-indeterminate
Selectors Level 4
# indeterminate

浏览器兼容性

BCD tables only load in the browser

参见