Forum Moderators: not2easy
3.11. UI element states pseudo classes
The UI (User Interface) element state pseudo classes [w3.org] disabled, enabled, checked and indeterminate apply to elements that can have such state through means outside of CSS. Either the user of scripting can set the state, of the state could be derived from the html intself.
Syntax: E:disabled
Syntax: E:enabled
Syntax: E:checked
Syntax: E:indeterminate
Example:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<style type="text/css">
button.style {
background-color: orange;
}
button.style:disabled {
background-color: red;
color: white;
}
button.style:enabled {
background-color: green;
color: yellow;
}
span {
background-color: orange;
}
input:checked + span {
background-color: blue;
color: white;
}
input:indeterminate + span {
background-color: red;
}
</style>
</head>
<body>
<form action="#">
<p>default:</p>
<button disabled="disabled">disabled</button>
<button>enabled</button>
<p>styled:</p>
<button class="style" disabled="disabled">disabled</button>
<button class="style">enabled</button>
<input type="checkbox" checked="checked" /><span>checked by default</span>
<input type="checkbox" /><span>not checked by default</span>
<input type="checkbox" id="here" /><span>made indeterminate by scripting</span>
</form>
<script type="text/javascript">
window.onload = function() {
document.getElementById("here").indeterminate = true;
}
</script>
</body>
</html>
Support:
:checked :disabled :enabled
:indeterminate
IE8.js adds support for all four selectors in IE6 and IE7
jQuery?: To be elaborated.
Practical use:
Enhance your forms!
[edited by: swa66 at 10:44 pm (utc) on July 6, 2009]