const total = CSS.px(10).add(CSS.px(5), CSS.px(2));
console.log(total.toString()); // "17px"CSSNumericValue: add() method / notebook
CSSNumericValue: add() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const mathSum = CSS.px(23).add(CSS.percent(4)).add(CSS.cm(3)).add(CSS.in(9));
console.log(mathSum.toString()); // "calc(23px + 4% + 3cm + 9in)"try {
CSS.px(1).add(CSS.s(1));
} catch (e) {
console.log(e instanceof TypeError); // true
}
try {
CSS.px(1).add(2);
} catch (e) {
console.log(e instanceof TypeError); // true
}