:optional
La pseudo-class CSS :optional
representa qualsevol element <input>
, <select>
o <textarea>
que no té l'atribut required
establert en ell.
/* Selecciona qualsevol <input> opcional */
input:optional {
border: 1px dashed black;
}
Aquesta pseudo-class és útil per als camps d'estil que no són obligatoris per enviar en un formulari.
Nota: La pseudo-class :required
selecciona els camps de formulari obligatoris.
Sintaxi
:optional
Exemples
Veure :invalid
com exemple.
Especificacions
Especificació | Estat | Comentari |
---|---|---|
HTML Living Standard The definition of ':optional' in that specification. |
Living Standard | Sense canvis. |
HTML5 The definition of ':optional' in that specification. |
Recommendation | Defineix la semàntica d'HTML i la validació de restriccions. |
Selectors Level 4 The definition of ':optional' in that specification. |
Working Draft | Sense canvis. |
CSS Basic User Interface Module Level 3 The definition of ':optional' in that specification. |
Recommendation | Defineix la pseudo-classe, 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! (en-US)
Descripció | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Suport bàsic | 10.0 | (Yes) | 4.0 (2) | 10 | 10.0 | 5.0 |
Descripció | Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Suport bàsic | 4.4 | (Yes) | 4.0 (2) | No support | 10.0 | 5.0 |
Vegeu també
- Altres pseudo-classes relacionades amb la validació:
:required
,:invalid
,:valid
- Validació de dades del formulari