Horje
How to do addition or subtraction on CSS Variables? Code Example
How to do addition or subtraction on CSS Variables?
:root {
  --margin: 50px;
  --margin--: calc(var(--margin) * -1));
 /* 
 while you may simply write like below
 but I love to use as above 
 coz, we'll only need to change value 
 in one place if needed
 */
 /* --margin--: -50px; */
}

.positive-margin {
  margin: var(--margin);
}
.negative-margin {
  margin-left: var(--margin--);
}
How to do addition or subtraction on CSS Variables?
: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 */
}




Css

Related
javascript typewriter effect left to right Code Example javascript typewriter effect left to right Code Example
studio 3t restore snapshot Code Example studio 3t restore snapshot Code Example
horizontal checkbox css Code Example horizontal checkbox css Code Example
delete a process in ubuntu Code Example delete a process in ubuntu Code Example
selectors combinators css Code Example selectors combinators css Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11