大网数据广告活动
Web 标准与前端开发

CSSMathInvert

· 52CE 我爱测

The **`CSSMathInvert`** interface of the CSS Typed Object Model API represents the inverse (reciprocal) of a CSSNumericValue.

CSS Typed Object Model API

The CSSMathInvert interface of the CSS Typed Object Model API represents the inverse (reciprocal) of a CSSNumericValue.

Constructor

  • CSSMathInvert.CSSMathInvert
    • : Creates a new CSSMathInvert object.

Instance properties

Also inherits properties from its parent interface, CSSMathValue.

  • CSSMathInvert.value
    • : Returns a CSSNumericValue object containing the value being inverted.

Static methods

Also inherits methods from its parent interface, CSSMathValue.

Instance methods

Also inherits methods from its parent interface, CSSMathValue.

Description

When you divide one CSSNumericValue by another using CSSNumericValue.div, if the divisor is a plain number, it can immediately be scaled into a value of the original type.

If the divisor is a different type, the result can't be resolved to a single object. In this case, the CSS Typed Object Model API represents the divisor as a CSSMathInvert.

Generally you won't construct a CSSMathInvert directly. It's produced when div() is called with a divisor that isn't a plain number: the result is a CSSMathProduct, and CSSMathInvert is the operand holding that divisor — found by walking the product's operands, or by checking CSSMathValue.operator for the string "invert".

CSSMathInvert serializes using CSS calc syntax, as calc(1 / <value>).

Examples

Constructing a CSSMathInvert with a non-number divisor

This example shows how you can use CSSNumericValue.div with a divisor that isn't a plain number to get a CSSMathProduct that has a CSSMathInvert as one of its operands. The value and serialization of that operand are also logged.

const product = CSS.px(200).div(CSS.percent(4));

console.log(product.constructor.name); // "CSSMathProduct"
console.log(product.values[1].constructor.name); // "CSSMathInvert"
console.log(product.values[1].value); // CSSUnitValue {value: 4, unit: "percent"}
console.log(product.toString()); // "calc(200px / 4%)"

Specifications

Browser compatibility

See also

  • CSSNumericValue.div
  • CSSMathNegate
  • CSSMathValue.operator

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。