What is the use of invalid selector?

清浅
Release: 2019-01-26 11:36:28
Original
4141 people have browsed it

The role of the invalid selector is to set a specific style when an illegal value is entered in the form element. The purpose is to remind the user that the entered value is incorrect.

The :invalid selector in CSS is mainly used Sets the specified style when the value in the form element is illegal.

What is the use of invalid selector?

【Recommended course: CSS Tutorial

Example: When the user input is not a legal value, the style will change to a red border

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title></title> 
<style>
input:invalid
{
	border:2px solid red;
}
</style>
</head>
<body>
<input type="email" value="" />

<p>请输入合法 e-mail 地址,查看样式变化。</p>

</body>
</html>
Copy after login

Rendering:

What is the use of invalid selector?

##Note: The :invalid selector only works on elements that can specify interval values, such as the min and max attributes in the input element, the correct email field, legal numeric fields, etc.

The above is the detailed content of What is the use of invalid selector?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template