CSSPositionTryRule
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.
Giao diện CSSPositionTryRule mô tả một đối tượng biểu thị at-rule @position-try at-rule.
Thuộc tính phiên bản
Kế thừa thuộc tính từ lớp tổ tiên CSSRule.
CSSPositionTryRule.nameRead only-
Biểu thị tên của tùy chọn position try được chỉ định bởi
<dashed-ident>của at-rule@position-try. CSSPositionTryRule.styleRead only-
Một đối tượng
CSSPositionTryDescriptorsbiểu thị các khai báo được đặt trong nội dung của at-rule@position-try.
Phương thức phiên bản
Không có phương thức cụ thể; kế thừa phương thức từ lớp tổ tiên CSSRule.
Ví dụ
CSS bao gồm at-rule @position-try với tên --custom-left và ba descriptor.
css
@position-try --custom-left {
position-area: left;
width: 20%;
max-width: 200px;
margin-right: 10px;
}
js
const myRules = document.styleSheets[0].cssRules;
const tryOption = myRules[0]; // a CSSPositionTryRule
console.log(tryOption); // "[object CSSPositionTryRule]"
console.log(tryOption.name); // "--custom-left"
console.log(tryOption.style); // "[object CSSPositionTryDescriptors]"
console.log(tryOption.style.maxWidth); // "200px"
Thông số kỹ thuật
| Specification |
|---|
| CSS Anchor Positioning Module Level 1> # csspositiontryrule> |