Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using sass lighten functions with variable not working

Tags:

css

sass

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 of lighten($color, $amount) must be a color on line 10 of assets/scss/base/typography.scss, in function lighten

How can I use lighten function with that variable? I need to use --text-color: #383143; that format for the color switcher purpose.

like image 337
Md Nurullah Avatar asked Dec 02 '19 12:12

Md Nurullah


People also ask

Can SCSS variable change dynamically?

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).

How do you lighten colors in sass?

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.

Does Sass support CSS variables?

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.

What is the correct way to define a variable in sass?

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.


1 Answers

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};
}
like image 54
Jacob Avatar answered Nov 15 '22 08:11

Jacob