3

I'm trying to make the 100% in filter: grayscale(100%); be a CSS variable so I can dynamically change it later with JavaScript.

--percent: 100%;
filter: grayscale(var(--percent));

This is not compiling with Dart sass. It's telling me:

Dart Sass failed with this error: $color: var(--percent) is not a color. filter: grayscale(var(--percent));

Which doesn't make any sense to me as it works just fine with normal CSS.

How can I get this normal CSS Variable to work with Dart Sass?

briann
  • 143
  • 7

1 Answers1

4

Because it conflicts with the grayscale function of Sass and Sass-specific functions can't handle CSS variables.

Use it this way:

--percent: 100%;
filter: #{"grayscale(var(--percent))"};
doğukan
  • 23,073
  • 13
  • 57
  • 69