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

瀏覽器相容性

另見