摘要
:required CSS 伪类 表示 任意 <input> 元素表示任意拥有required属性的 <input> 或 <textarea> 元素使用它. 它允许表单在提交之前容易的展示必填字段并且渲染其外观.
:optional伪类可用于表单可选元素提供外观.
语法
:required { style properties }
例子
查看示例 :invalid .
规范
| Specification | Status | Comment |
|---|---|---|
| WHATWG HTML Living Standard :required |
Living Standard | No change. |
| HTML5 :required |
Recommendation | Defines the semantic regarding HTML and constraint validation. |
| Selectors Level 4 :required |
Working Draft | No change. |
| CSS Basic User Interface Module Level 3 :required |
Candidate Recommendation | Defines the pseudo-class, but not the associated semantic. |
浏览器兼容
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 10.0 | 4.0 (2) | 10 | 10.0 | 5.0 |
| Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | ? | 4.0 (2) | 未实现 | 10.0 | 5.0 |