CSSNestedDeclarations: style property
Baseline
2024
Newly available
Since December 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Thuộc tính chỉ đọc style của giao diện CSSNestedDeclarations đại diện cho các kiểu liên quan đến các quy tắc lồng nhau.
Giá trị
Một đối tượng CSSStyleProperties.
Mặc dù bản thân thuộc tính style là chỉ đọc theo nghĩa bạn không thể thay thế đối tượng CSSStyleProperties, bạn vẫn có thể gán cho thuộc tính style trực tiếp, tương đương với việc gán cho thuộc tính cssText của nó. Bạn cũng có thể sửa đổi đối tượng CSSStyleProperties bằng cách sử dụng phương thức setProperty() và removeProperty().
Ví dụ
Stylesheet này chứa cssRules lồng nhau.
console.log đầu tiên hiển thị style cấp cao nhất, cái thứ hai hiển thị truy vấn @media lồng nhau với kiểu lồng nhau của nó và cái cuối cùng hiển thị kiểu lồng nhau được khai báo sau truy vấn @media.
.foo {
font-size: 1.2rem;
@media screen {
color: tomato;
background-color: darkgrey;
}
color: black;
}
let myRules = document.styleSheets[0].cssRules;
console.log(myRules[0].style);
// { "0": "font-size" }
console.log(myRules[0].cssRules[0].cssRules[0].style);
// { "0": "color", "1": "background-color" }
console.log(myRules[0].cssRules[1].style);
// { "0": "color" }
Thông số kỹ thuật
| Specification |
|---|
| CSS Nesting Module Level 1> # dom-cssnesteddeclarations-style> |