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

CSSMathValue: operator property

· 52CE 我爱测

The **`operator`** read-only property of the CSSMathValue interface returns the operator that the current subtype represents. For example, if the current `CSSMathValue` subtype is `CSSMathSum`, this property will return the string `"sum"`.

CSS Typed Object Model API

The operator read-only property of the CSSMathValue interface returns the operator that the current subtype represents. For example, if the current CSSMathValue subtype is CSSMathSum, this property will return the string "sum".

Value

A String.

Interface Value
CSSMathSum "sum"
CSSMathProduct "product"
CSSMathMin "min"
CSSMathMax "max"
CSSMathClamp "clamp"
CSSMathNegate "negate"
CSSMathInvert "invert"

Examples

Basic usage

This example shows how the operator property identifies the operation represented by a calc() value's CSSMathValue subtype, including for a nested value.

HTML

<div id="demoBox">Text</div>
<pre id="log"></pre>

CSS

width is set using a calc() subtraction, which is represented as a CSSMathSum whose second term is negated.

#demoBox {
  width: calc(50% - 0.5vw);
}
#log {
  height: 80px;
  overflow: scroll;
  padding: 0.5rem;
  border: 1px solid black;
}

JavaScript

const logElement = document.querySelector("#log");
function log(text) {
  logElement.innerText += `${text}\n`;
}

We read the width value using Element.computedStyleMap(), then log its operator and the operator of its nested value.

const styleMap = document.querySelector("#demoBox").computedStyleMap();
const width = styleMap.get("width");

log(`operator: ${width.operator}`);
log(`nested value operator: ${width.values[1].operator}`);

Result

width is represented by a CSSMathSum object whose operator is "sum", because calc(50% - 0.5vw) is represented as an addition of 50% and the negation of 0.5vw. The second nested value's operator is "negate", reflecting that negation.

Basic usage

Specifications

Browser compatibility

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

资料来源与适用范围

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

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

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