📜  如何对 CSS 变量进行加减运算? - CSS 代码示例

📅  最后修改于: 2022-03-11 14:47:47.789000             🧑  作者: Mango

代码示例2
:root {
  --margin: 50px;
}

body {
  margin: 0 100px;
  border:1px solid;
}

.box-1 {
  background: red;
  height: 100px;
  width: 200px;
  margin-left: calc(-1 * var(--margin));
}

.box-2 {
  background: green;
  height: 100px;
  width: 200px;
  margin-left: calc(-1 * (-1 * var(--margin))); /* You can also nest calculation */
}