CSSPositionTryRule: thuộc tính style
Baseline
2026
Newly available
Since January 2026, 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 CSSPositionTryRule chứa một đối tượng CSSPositionTryDescriptors biểu thị các descriptor có sẵn trong nội dung quy tắc @position-try.
Giá trị
Một đối tượng CSSPositionTryDescriptors.
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 CSSPositionTryDescriptors, bạn vẫn có thể gán trực tiếp cho thuộc tính style, 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 CSSPositionTryDescriptors bằng cách sử dụng các phương thức setProperty() và removeProperty().
Ví dụ
CSS bao gồm at-rule @position-try với tên --custom-right và ba descriptor.
@position-try --custom-bottom {
top: anchor(bottom);
min-width: 100px;
margin-top: 10px;
}
const myRules = document.styleSheets[0].cssRules;
const tryOption = myRules[0]; // a CSSPositionTryRule
console.log(tryOption.style.top); // "anchor(bottom)"
console.log(tryOption.style["min-width"]); // "100px"
console.log(tryOption.style.positionArea); // ""; no position-area specified
Thông số kỹ thuật
| Specification |
|---|
| CSS Anchor Positioning Module Level 1> # dom-csspositiontryrule-style> |