:indeterminate CSS 伪类 表示状态不确定的表单元素:

/* Selects any <input> whose state is indeterminate */
input:indeterminate {
  background: lime;
}

根据上述例子(选择器)选中的元素是:

 

语法

:indeterminate

示例

Checkbox & radio button

CSS

input, span {
  background: red;
}

:indeterminate, :indeterminate + label {
  background: lime;
}

HTML

<div>
  <input type="checkbox" id="checkbox">
  <label for="checkbox">Background should be green</label>
</div>
<div>
  <input type="radio" id="radio">
  <label for="radio">Background should be green</label>
</div>

JavaScript

var inputs = document.getElementsByTagName("input");
for(var i = 0; i < inputs.length; i++) {
  inputs[i].indeterminate = true;
}

Progress bar

CSS

progress {
  margin: 4px;
}

progress:indeterminate {
  opacity: 0.5;
  background-color: lightgray;
  box-shadow: 0 0 2px 1px red;
}

HTML

<progress>

结果

规范

Specification Status Comment
HTML Living Standard
:indeterminate
Living Standard No change
HTML5
:indeterminate
Recommendation Defines the semantic regarding HTML and constraint validation.
Selectors Level 4
:indeterminate
Working Draft No change
CSS Basic User Interface Module Level 3
:indeterminate
Recommendation Defines the pseudo-class, but not the associated semantic.

浏览器兼容性

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support Yes Yes Yes Yes Yes Yes
type="checkbox" ? Yes3.6910.63
type="radio"39 No151 No ? No2
<progress>6 Yes610 ? Yes
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support ? ? Yes Yes ? ? ?
type="checkbox" ? ? Yes4 ? ? ?
type="radio"39 ? No151 ? No2 ?
<progress> ? ? Yes6 ? ? ?

1. See Edge bug 7124038.

2. See WebKit bug 156270.

文档标签和贡献者

此页面的贡献者: Ritr, nDos, holynewbie
最后编辑者: Ritr,