CSSPositionTryRule

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

CSSPositionTryRule 接口描述了一个代表 @position-try at-rule 的对象。

CSSRule CSSPositionTryRule

实例属性

继承自其祖先 CSSRule 的属性。

CSSPositionTryRule.name 只读

表示 @position-try at-rule 的 <dashed-ident> 指定的位置尝试选项的名称。

CSSPositionTryRule.style 只读

一个 CSSPositionTryDescriptors 对象,它代表 @position-try at-rule 主体中设置的声明。

实例方法

没有特定的方法;继承自其祖先 CSSRule 的方法。

示例

CSS 包含一个 @position-try at-rule,其名称为 --custom-left,并带有三个描述符。

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"

规范

规范
CSS 锚点定位
# csspositiontryrule

浏览器兼容性

另见