everyone!
I've got this files structure
_utils.scss
_variables.scss
styles.scss
in styles.scss I import every partial with:
@use "utils" as *;
@use "variables";
body {
min-height: 100vh;
background-color: var(--cl-primary);
font-size: var(--fs-normal);
}
The content of _utils.scss is this:
@use "sass:math";
/// Converts PX to REM
/// @access public
/// @param {string} $size - Value to be converted in PX.
/// @returns {string} - Returns REM string.
/// @example font-size: rem(24px);
/// @returns font-size: 1.5rem;
@function toRem($size) {
$remSize: math.div($size, 16px);
@return #{$remSize}rem;
}
And the content of _variables.scss is this:
:root {
--cl-primary: #3829e0;
--cl-primary-tint: #e0e8ff;
--fs-normal: toRem(32px);
}
Questions:
Why on the webpage the css custom property --fs-normal is evaluated to "toRem(32px)" instead of 2rem?
2nd question: what should I do in order to get --fs-normal to be evaluated to 2rem?
Thank you all!
EDIT: i tried to reproduce a given solution in a fiddle: https://jsfiddle.net/mihai3636/fcjspt1v/24/
EDIT2:
ANSWER:
Beside string interpolation I should have added this line inside _variables.scss:
@use "./utils" as *;
Please read the last comment from Invulner on the answer
So _variables.scss should look like this in order to work:
@use "./utils" as *;
:root {
--cl-primary: #3829e0;
--cl-primary-tint: #e0e8ff;
--fs-normal: #{toRem(32px)};
}