23

I am trying to create dynamic values, but have failed so far. The created pixel value seems to lose the ability to be used in calculations.

$numericValue: 30;

$pixelValue: $numericValue+px;
// also tried $pixelValue: #{$numericValue}px;

$calc: $pixelValue * 2;
// also tried $calc: unquote($pixelValue) * 2;

This throws an error

Syntax error: Undefined operation: "30px times 2"

cimmanon
  • 67,211
  • 17
  • 165
  • 171
owzim
  • 885
  • 2
  • 9
  • 19

2 Answers2

31

The trick is to use * 1px when you want to add a unit. Using +px or interpolation (#{$numericValue}px) turns it into a string.

$numericValue: 30;

$pixelValue: $numericValue * 1px;

$calc: $pixelValue * 2;
cimmanon
  • 67,211
  • 17
  • 165
  • 171
bookcasey
  • 39,223
  • 13
  • 77
  • 94
-1

You need to define the unit you will use. If you are working with pixels you can create dynamic values adding px to the $numericValue.

$numericValue: 30px;
$pixelValue: $numericValue;
$calc: $pixelValue * 2;
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Rach Glucio
  • 80
  • 10