值
包含層名稱的字串,如果層是匿名的,則為 ""。
示例
HTML
html
<output></output> <output></output>
CSS
css
output {
display: block;
}
@layer special {
div {
color: rebeccapurple;
}
}
@layer {
div {
color: black;
}
}
JavaScript
js
const item1 = document.getElementsByTagName("output")[0];
const item2 = document.getElementsByTagName("output")[1];
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[1]; // A CSSLayerBlockRule
const anonymous = rules[2]; // An anonymous CSSLayerBlockRule
item1.textContent = `The first CSSLayerBlockRule defines the "${layer.name}" layer.`;
item2.textContent = `A second CSSLayerBlockRule defines a layer with the following name: "${anonymous.name}".`;
結果
規範
| 規範 |
|---|
| CSS 級聯與繼承第五級 # dom-csslayerblockrule-name |
瀏覽器相容性
載入中…
另見
@layer的語句宣告由CSSLayerStatementRule表示。- 如何在 CSS 中 建立命名級聯層。