CSSSupportsRule

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.

实例属性

继承其祖先 CSSConditionRuleCSSGroupingRuleCSSRule 的属性。

实例方法

继承其祖先 CSSConditionRuleCSSGroupingRuleCSSRule 的方法。

示例

CSS 中包含了一个使用 @supports At 规则的 CSS 特性查询,其中含有一条样式规则。这将会是 document.styleSheets[0].cssRules 返回的第一个 CSSRule。因此,myRules[0] 返回的是一个 CSSSupportsRule 对象。

css
@supports (display: grid) {
  body {
    color: blue;
  }
}
js
let myRules = document.styleSheets[0].cssRules;
console.log(myRules[0]); // 一个表示特性查询的 CSSSupportsRule 对象。

规范

Specification
CSS Conditional Rules Module Level 3
# the-csssupportsrule-interface

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
CSSSupportsRule

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Has more compatibility info.

参见