首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

:可选的 | :optional

:optionalCSS伪类?表示任意没有required属性的?<input>或?<textarea>?元素使用它. 它允许表单容易的展示可选字段并且渲染其外观.

代码语言:javascript
复制
/* Selects <input> elements, but only if they are */
/* optional, i.e. have not got required set on them */
input:optional {
  border: 1px dashed black;
}

为必填字段设置外观,请使用:required伪类.

语法

代码语言:javascript
复制
:optional

示例

查看示例:invalid.

规范

Specification

Status

Comment

HTML Living StandardThe definition of ':optional' in that specification.

Living Standard

No change.

HTML5The definition of ':optional' in that specification.

Recommendation

Defines the semantic regarding HTML and constraint validation.

Selectors Level 4The definition of ':optional' in that specification.

Working Draft

No change.

CSS Basic User Interface Module Level 3The definition of ':optional' in that specification.

Candidate Recommendation

Defines the pseudo-class, but not the associated semantic.

浏览器兼容性

Feature

Chrome

Edge

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

10.0

(Yes)

4.0 (2)

10

10.0

5.0

Feature

Android

Edge

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

4.4

(Yes)

4.0 (2)

No support

10.0

5.0

另见

  • :required
  • :invalid
  • :valid

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com