Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SCSS behavior with negative margin [duplicate]

Tags:

sass

Let's take this SCSS code :

$margin: 10px;
.use_value {
  margin: 10px 0 0 10px;
}
.use_var {
  margin: $margin 0 0 $margin;
}
.use_negative_var {
  margin: -$margin 0 0 -$margin;
}

I expected .use_value, .use_var and .use_negative_var to be identic, but here's the result :

.use_value {
  margin: 10px 0 0 10px;
}
.use_var {
  margin: 10px 0 0 10px;
}
.use_negative_var {
  margin: 10px 0 -10px; 
}

Why is there a missing 0 in .use_negative_var ?

like image 437
zessx Avatar asked Apr 20 '26 12:04

zessx


1 Answers

You have to interpolate the variable:

$margin: 10px;

.use_value {
  margin: 10px 0 0 10px;
}

.use_var {
  margin: $margin 0 0 $margin;
}

.use_negative_var {
  margin: -#{$margin} 0 0 -#{$margin};
}
like image 176
Joseph Silber Avatar answered Apr 26 '26 04:04

Joseph Silber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!