I am using SASS in my project with
Here if my variables code
:root, [data-theme="default"] {
--text-color: #383143;
}
$text-color: var(--text-color);
i am using that variable with lighten function like bellow,
body {
color: lighten($text-color, 10%);
}
I am getting the following error,
Error: argument
$color
oflighten($color, $amount)
must be a color on line 10 of assets/scss/base/typography.scss, in functionlighten
How can I use lighten function with that variable? I need to use --text-color: #383143; that format for the color switcher purpose.
SCSS is compiled to CSS during compile time, and SCSS variables are replaced with resolved value during compile time, which means there is no way to change the variable during run time. However, CSS variables just sits there during run time, and you can dynamically CRUD them during run time with JavaScript (Web API).
Using lighten() and darken() in SASS As the names suggest, given a colour and percentage, these functions will return a colour lighter or darker respectively.
Sass variables are all compiled away by Sass. CSS variables are included in the CSS output. CSS variables can have different values for different elements, but Sass variables only have one value at a time.
The basic syntax for defining a variable is simple: Just use a $ before the variable name and treat its definition like a CSS rule: Sass Variable Syntax: $<variable name>:<value>; The following declares a variable named large-font.
You can't use SASS variables in CSS variables as those are compiled before CSS is running. To solve this you could move the CSS variable to be defined by SASS, like this
$text-color: #383143;
:root, [data-theme="default"] {
--text-color: #{$text-color};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With