CSSLayerBlockRule

Baseline 已广泛支持

此特性已经十分成熟,可在许多设备和浏览器版本上使用。自 2022 年 3 月起,它已在各浏览器中可用。

CSSLayerBlockRule 表示一个 @layer 块规则。

CSSRule CSSGroupingRule CSSLayerBlockRule

实例属性

继承其祖先 CSSGroupingRuleCSSRule 的属性。

CSSLayerBlockRule.name 只读

一个包含关联的级联层名称的字符串。

实例方法

继承其祖先 CSSGroupingRuleCSSRule 的方法。

示例

HTML

html
<p>I am displayed in <code>color: rebeccapurple</code>.</p>

CSS

css
@layer special {
  p {
    color: rebeccapurple;
  }
}

JavaScript

js
const item = document.getElementsByTagName("p")[0];
const rules = document.styleSheets[1].cssRules;
// Note that stylesheet #1 is the stylesheet associated with this embedded example,
// while stylesheet #0 is the stylesheet associated with the whole MDN page

const layer = rules[0]; // A CSSLayerBlockRule

item.textContent = `The CSSLayerBlockRule is for the "${layer.name}" layer`;

结果

规范

规范
CSS 级联与继承第五级
# csslayerblockrule

浏览器兼容性

另见