CSSLayerStatementRule: nameList 屬性

Baseline 已廣泛支援

此特性已經十分成熟,可在許多裝置和瀏覽器版本上使用。自 2022 年 3 月起,它已在各瀏覽器中可用。

CSSLayerStatementRule 介面的只讀 nameList 屬性返回關聯的級聯層名稱列表。這些名稱不可修改。

一個字串的 Array,每個字串代表由 @layer 語句規則表示的級聯層。

示例

HTML

html
<div></div>

CSS

css
@layer layerName, layerName2;

@layer layerName3 {
  div {
    font-family: serif;
  }
}

JavaScript

js
const item = document.getElementsByTagName("div")[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 layerStatementRule = rules[0]; // A CSSLayerStatementRule
const layerBlockRule = rules[1]; // A CSSLayerBlockRule; no nameList property.

item.textContent = `@layer declares the following layers: ${layer.nameList.join(
  ", ",
)}.`;

規範

規範
CSS 級聯與繼承第五級
# dom-csslayerstatementrule-namelist

瀏覽器相容性

另見