Home  >  Article  >  Web Front-end  >  What is the use of invalid selector?

What is the use of invalid selector?

清浅
清浅Original
2019-01-26 11:36:284124browse

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>

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!

Statement:
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