Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第 123 期(W3C标准-CSS-伪类&伪元素):表单验证伪类 #126

Open
wingmeng opened this issue Oct 13, 2019 · 0 comments
Open

第 123 期(W3C标准-CSS-伪类&伪元素):表单验证伪类 #126

wingmeng opened this issue Oct 13, 2019 · 0 comments

Comments

@wingmeng
Copy link
Collaborator

form 内置验证有一些 CSS 伪类,如 :required, :optional:valid:invalid,这些伪类对于突出显示用户的字段错误非常有用。

/* 匹配所有输入表单项 */
input {border: 1px solid #ccc;}

/* 匹配非必填的表单项(即没有 required 属性) */
input:optional {border-color: #666;}

/* 匹配必填的输入表单项 */
input:required {border-color: blue;}

/* 匹配合法值的输入表单项(验证通过) */
input:valid {border-color: green;}

/* 匹配非法值的输入表单项(验证未通过) */
input:invalid {border-color: red;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant