When working with CSS sizing, I prefer using rem units with pixel fallbacks and am currently creating mixins to streamline the process. For setting font sizes, it's a simple task:
@mixin font-size($size) {
font-size: $size + px;
font-size: ($size / 10) + rem;
}
However, when dealing with padding, margins, and similar properties, the mixin needs to accept variable arguments. The Sass documentation mentions that this is achievable here.
The issue arises when using the following mixin - instead of dividing by 10, the numbers are being combined with a slash. For example:
@mixin padding($padding...) {
padding: $padding + px;
padding: ($padding / 10) + rem;
}
.class {
@include padding(24);
}
This results in:
.class {
padding: 24px;
padding: 24/10rem;
}
What I actually want is:
.class {
padding: 24px;
padding: 2.4rem;
}
Is there a way to ensure that Sass recognizes the variables as numbers so that the division operator works correctly?
Upon further testing, I noticed that the concatenation only occurs on the last variable.