CSSLayerStatementRule
CSSLayerStatementRule 表示一个 @layer 语句规则。与 CSSLayerBlockRule 不同,它不包含其他规则,仅仅通过提供名称来定义一个或多个层。
此规则允许显式声明 CSS 文件开头处以明显方式出现的层顺序:层顺序由每个层名称首次出现的顺序定义。通过语句声明它们允许读者理解层顺序。它还允许内联层和导入的层交错,这在使用 CSSLayerBlockRule 语法时是不可能的。
实例属性
还继承了其父接口 CSSRule 的属性。
CSSLayerStatementRule.nameList只读- 一个字符串数组,代表规则定义的每个级联层的名称
示例
HTML
html
<p></p>
CSS
css
@layer layerName, layerName2;
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 CSSLayerStatementRule
item.textContent = `The CSS @layer statement declares the following layers: ${layer.nameList.join(
", ",
)}.`;
结果
规范
| 规范 |
|---|
| CSS 级联与继承第五级 # csslayerstatementrule |
浏览器兼容性
加载中…