CSS.supports() - Web APIs 编辑
The CSS.supports()
method returns a Boolean
value indicating if the browser supports a given CSS feature, or not.
Syntax
CSS.supports(propertyName, value); CSS.supports(supportCondition);
Parameters
There are two distinct sets of parameters. The first one allows to test the support of a pair property-value:
propertyName
- A
DOMString
containing the name of the CSS property to check. value
- A
DOMString
containing the value of the CSS property to check.
The second syntax takes one parameter matching the condition of @supports
:
supportCondition
- A
DOMString
containing the condition to check.
Return value
true
if the browser supports the rule, otherwise false
.
Examples
result = CSS.supports("text-decoration-style", "blink");
result = CSS.supports("display: flex");
result = CSS.supports("(--foo: red)");
result = CSS.supports(`(transform-style: preserve) or (-moz-transform-style: preserve) or
(-o-transform-style: preserve) or (-webkit-transform-style: preserve)`);
// result is true or false
Specifications
Specification | Status | Comment |
---|---|---|
CSS Conditional Rules Module Level 3 The definition of 'CSS: supports()' in that specification. | Candidate Recommendation | Initial definition. |
Browser compatibility
BCD tables only load in the browser
See also
- The
@supports
at-rule that allows for the same functionality but in a declarative way. - The
CSSSupportsRule
CSSOM class allowing to manipulate@supports
at-rules.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论