valid
On this page
CSS :valid Pseudo Class
The :valid pseudo-class selects <form> elements with a value that validates according to the element’s settings.
The :valid selector only works for form <input> elements with min and max attributes, email fields with a legal email, number fields with a numeric value or required fields with not empty value. (属性、具有合法电子邮件的电子邮件字段、具有数值的数字字段或具有非空值的必填字段。)
Version
Version (版本)
HTML Living Standard (生活水平)
HTML5
Selectors Level 4 (选择器级别4)
Syntax
Syntax (语法)
:valid {
css declarations;
}
Example of the :valid selector:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
input {
border: 1px solid #cccccc;
padding: 5px 10px;
}
input:valid {
background-color: #eeeeee;
}
</style>
</head>
<body>
<h2>:valid selector example</h2>
<form>
<input type="email" value="[email protected]">
</form>
</body>
</html>
In the given example when typing an illegal e-mail address, the styling disappears. (在给定的示例中,键入非法电子邮件地址时,样式消失。)