La pseudo-class CSS :enabled
representa qualsevol element habilitat. Un element està habilitat si es pot activar (seleccionar, fer clic en, teclejar, etc.) o acceptar l'enfocament. L'element també té un estat de deshabilitat, en el qual no es pot activar o acceptar l'enfocament.
/* Selecciona qualsevol <input> habilitat */
input:enabled {
color: blue;
}
Sintaxi
:enabled
Exemple
El següent exemple fa que el color del text i botó <input>
sigui verd quan està habilitat, i gris quan està deshabilitat. Això ajuda a l'usuari a comprendre amb quins elements pot interactuar.
HTML
<form action="url_of_form">
<label for="FirstField">First field (enabled):</label>
<input type="text" id="FirstField" value="Lorem"><br>
<label for="SecondField">Second field (disabled):</label>
<input type="text" id="SecondField" value="Ipsum" disabled="disabled"><br>
<input type="button" value="Submit">
</form>
CSS
input:enabled {
color: #2b2;
}
input:disabled {
color: #aaa;
}
Resultat
Especificacions
Especificació | Estat | Comentari |
---|---|---|
HTML Living Standard The definition of ':enabled' in that specification. |
Living Standard | Cap canvi. |
HTML5 The definition of ':enabled' in that specification. |
Recommendation | Defineix la semàntica per a HTML i formularis. |
Selectors Level 4 The definition of ':enabled' in that specification. |
Working Draft | Cap canvi . |
CSS Basic User Interface Module Level 3 The definition of ':enabled' in that specification. |
Recommendation | Enllaços a selectors Nivell 3. |
Selectors Level 3 The definition of ':enabled' in that specification. |
Recommendation | Defineix la pseudo-class, però no la semàntica associada. |
Navegadors compatibles
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Descripció | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Suport bàsic | 1.0 | (Yes) | 1.0 (1.7 or earlier) | 9.0 | 9.0 | 3.1 |
Descripció | Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Suport bàsic | 2.1 | (Yes) | 1.0 (1) | 9.0 | 9.5 | 3.1 |