English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Complete CSS Selector Reference Manual
If the value entered in the input element is valid, set it to yellow:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Basic Tutorial(oldtoolbag.com)</title>/title> <style> input:valid { background-color: yellow; } </style> </head> <body> <h3>:valid selector example demonstration.</h3> <input type="email" value="[email protected]"> /> <p>Please enter an invalid e-email address, see style changes.</p> </body> </html>Test to see ‹/›
:valid selector sets the specified style when the value of a form element needs to be validated according to the specified conditions.
Note: :valid selector only affects elements that can specify a range of values, such as min and max attributes in input elements, and correct email fields, valid numeric fields, etc.
The numbers in the table indicate the first browser version that supports this attribute.
Selector | |||||
---|---|---|---|---|---|
:valid | 10.0 | 10.0 | 4.0 | 5.0 | 10.0 |
:valid { css declaration; }
CSS Selector :invalid