2

I have a SASS variable:

$default-padding: 15px

I want to use this to set a CSS width property using the calc function.

I have various calculations to make based on the value of the $default-padding variable. For Example, the width would be 100% - (2 * $default-padding). As there is padding on the left and on the right.

I am trying to set a local variable (using Bourbon's strip-unit method):

$default-padding-left-and-right: #{(strip-unit($default-padding) * 2)}px;

I would expect the result of this variable to be 30px in this use case, and I want to use it in the following rule:

.popup {
    width: calc(100% - #{$default-padding-left-and-right});
}

This doesn't work, the resultant CSS is:

.popup {
    width: calc(100% - strip-unit(15px)px);
}

Any ideas what I'm doing wrong?

Anton Rand
  • 322
  • 5
  • 20

2 Answers2

7

Two things:

  1. it seems like the strip-unit function is not found (why the function name is printed out)
  2. you should not interpolate the $default-padding-left-and-right (it turns the variable value into a string) – use multiply instead.

Example :

@function strip-unit($num) { @return $num / ($num * 0 + 1); }

$default-padding: 15px;
$default-padding-left-and-right: strip-unit($default-padding) * 2px;

.popup {
  width: calc(100% - #{$default-padding-left-and-right});
} 

Output:

.popup {
  width: calc(100% - 30px);
}
Jakob E
  • 4,476
  • 1
  • 18
  • 21
  • Thank you, not sure why strip-unit isn't found. It's only not found if I do a multiplication on the result. – Anton Rand Feb 15 '17 at 12:59
0

The Bourbon function is strip-units not strip-unit - changing this should resolve your issue

Mike Harrison
  • 1,020
  • 2
  • 15
  • 42
  • 1
    I'm using Bourbon 4.3: WARNING: [Bourbon] [Deprecation] `strip-units` is deprecated and will be removed in 5.0.0. Use the renamed `strip-unit` function instead. – Anton Rand Feb 15 '17 at 13:00