:indeterminate - CSS: Cascading Style Sheets 编辑

The :indeterminate CSS pseudo-class represents any form element whose state is indeterminate, such as checkboxes which have their HTML indeterminate attribute set to true, radio buttons which are members of a group in which all radio buttons are unchecked, and indeterminate <progress> elements.

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

Elements targeted by this selector are:

Syntax

:indeterminate

Examples

Checkbox & radio button

This example applies special styles to the labels associated with indeterminate form fields.

HTML

<div>
  <input type="checkbox" id="checkbox">
  <label for="checkbox">This label starts out lime.</label>
</div>
<div>
  <input type="radio" id="radio">
  <label for="radio">This label starts out lime.</label>
</div>

CSS

input:indeterminate + label {
  background: lime;
}

JavaScript

var inputs = document.getElementsByTagName("input");

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

Progress bar

HTML

<progress>

CSS

progress {
  margin: 4px;
}

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

Result

Specifications

SpecificationStatusComment
HTML Living Standard
The definition of ':indeterminate' in that specification.
Living StandardNo change.
HTML5
The definition of ':indeterminate' in that specification.
RecommendationDefines the semantics of HTML and constraint validation.
Selectors Level 4
The definition of ':indeterminate' in that specification.
Working DraftNo change.

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:119 次

字数:5812

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文