CSSUnitValue: unit 属性

可用性有限

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

CSSUnitValue.unitCSSUnitValue 接口的一个只读属性,它返回一个字符串,指示单位的类型。

字符串。

示例

以下示例通过单独的 CSSUnitValue 构造函数创建了一个 CSSPositionValue,然后查询了 CSSUnitValue.unit

js
const pos = new CSSPositionValue(
  new CSSUnitValue(5, "px"),
  new CSSUnitValue(10, "em"),
);

console.log(pos.x.unit); // "px"
console.log(pos.y.unit); // "em"

规范

规范
CSS 类型化 OM Level 1
# dom-cssunitvalue-unit

浏览器兼容性

另见