Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use css variable with scss darken and ligthen filter

Tags:

css

sass

I would like to use scss lighten() and darken() function with CSS4 var.

Like this :

box-shadow: inset 0px -2px 50px 45px darken(var(--colorbtn),20%);

It seems not working, gulp write this:

Error: $color: "var(--colorbtn)" is not a color for `darken'

Its not possible to do that?

like image 765
Dujard Avatar asked Sep 23 '16 07:09

Dujard


People also ask

Can you use CSS variables with sass?

SASS is a CSS extension that lends superpower and elegance to this formal simple style language. SASS gives you the ability to use variables, nested rules, mixins, inline imports, and more, all with fully CSS-compliant syntax.

How do I color a variable in SCSS?

$color-red: #FF0000; $color-green: #00FF00; $color-blue: #0000FF; Remember, in order to use variables, or any of the benefits of SCSS for that matter, the stylesheet must have the '. scss' extension, and a preprocessor must be part of your website build system.

Can you change SCSS variable value 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 I change variables in SCSS?

A Sass variable must be initialized with a value. To change the value, we simply replace the old value with a new one. A variable that's initialized inside a selector can only be used within that selector's scope. A variable that's initialized outside a selector can be used anywhere in the document.


1 Answers

This can't really work because SASS is a preprocessor, and CSS custom properties can be dynamically changed at run-time. For SASS to be able to preprocess this with darken, it would have to replace the custom property with a static value, in which case the usefulness of the custom property is lost.

like image 135
Andy E Avatar answered Oct 14 '22 16:10

Andy E