-
Notifications
You must be signed in to change notification settings - Fork 8.1k
/
index.md
57 lines (40 loc) · 1.49 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
title: CSS.supports()
slug: Web/API/CSS/supports_static
---
{{APIRef("CSSOM")}}
**`CSS.supports()`** 静态方法返回一个{{domxref("Boolean")}}值,用来校验浏览器是否支持一个给定的 CSS 特性。
## 语法
```plain
boolValue = CSS.supports(propertyName, value);
boolValue = CSS.supports(supportCondition);
```
### 参数
有两种不同的传值形式。第一种用来检验浏览器对于一对“属性 - 属性值”的支持:
- _propertyName_
- : 一个包含要检查的 CSS 属性名称的{{domxref("DOMString")}}。
- _value_
- : 一个包含要检查的 CSS 属性值的{{domxref("DOMString")}}。
第二种语法需要一个匹配{{cssxref("@supports")}}条件的参数:
- _supportCondition_
- : 一个包含了检查条件的{{domxref("DOMString")}}。
## 实例
```js
result = CSS.supports("text-decoration-style", "blink");
result = CSS.supports("display", "flex");
result = CSS.supports("--foo", "red");
result = CSS.supports("(--foo: red)");
result = CSS.supports("( transform-origin: 5% 5% )");
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}}
## 浏览器兼容性
{{Compat}}
## 参见
- {{cssxref("@supports")}} at-rule 允许以声明的方式,使用相同的功能。
- {{domxref("CSSSupportsRule")}} CSSOM 类允许在规则中操作{{cssxref("@supports")}}。