Adding a unit to a number in Sass

后端 未结 2 1270
说谎
说谎 2020-11-22 10:03

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         


        
相关标签:
2条回答
  • 2020-11-22 10:41

    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;
    
    0 讨论(0)
  • 2020-11-22 10:49

    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;
    
    0 讨论(0)
提交回复
热议问题