2

Any reason why this isn't working?

:root {
--color-white: 0 0% 100%;
}

color: hsla(var(--color-white) 1);

I'm getting: SCSS processing failed: file "_page.scss", line 5, col 16: Function hsla is missing argument $saturation.

I also tried

color: #{hsla(var(--color-white) 1)};

which still does not work.

3
  • Might this be caused by a name clash between the CSS native hsla function and the SASS global hsla function? There is a way to differentiate between them but I can't recall how. Commented Apr 22, 2021 at 8:19
  • Just to clarify: you mean to use the css native runtime function, right? Because the sass compile step can't possibly interpret css custom vars (as their values are determined during runtime and depend on element nesting). Commented Apr 22, 2021 at 8:25
  • I found the fix to the name clash, added below as answer. Commented Apr 22, 2021 at 8:44

4 Answers 4

1

Try like below. You need comma with hsla() using the old syntax

:root {
--color-white: 0, 0%, 100%;
}

.box {
  color: hsla(#{var(--color-white), 1});
}

Or use the new syntax where you need / before the alpha

:root {
--color-white: 0 0% 100%;
}

.box {
  color: hsl(#{var(--color-white) / 100%});
}

Reference: https://www.w3.org/TR/css-color-4/#the-hsl-notation

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the note on the new syntax and using hsl() over hsla() (I want to stay current). However, using color: hsl(#{var(--color-white) / 100%}); still gives me SCSS processing failed: file "_page.scss", line 6, col 16: Function hsl is missing argument $saturation.
@Bice maybe check the compiler version. Try the code here: sassmeister.com and it will work fine
This shows it's still not working from sassmeister (gist saved from sassmeister): gist.github.com/bradryanbice/259b97822d1098c1b8436bf22d732b03
@Bice from what you are showing me, it seems to work fine. the output hsl(var(--color-white)/100%) is correct, what you want to get?
It ended up being my compiler version. I switched to a newer version of Dart Sass and all is fixed. Thank you!
|
1

SASS attempts to compile the styles with a SASS-specific hsla() function. However, hsla() is also a native CSS function, so you can use string interpolation to bypass the SASS function.

:root {
  --color-white: 0 0% 100%;
}

div {
    /* This is valid CSS, but will fail in a scss compilation */
    color: hsla(var(--color-white) 1);
    
    /* This is valid scss, and will generate the CSS above */
    color: #{'hsla(var(--color-white) 1)'};
}

Taken from this answer on SO.

Comments

0

hsla() takes four inputs and the punctuation needs to be accurate or none of it will work. No hash tags are needed:

  --color: 0, 100%, 50%;
    color: hsla(var(--color), 1);

This 100% works (pun intended).

2 Comments

It 100% does not :)
Sure it does. Here's the pen codepen.io/javascript-examples/pen/QWdJmWG
0

Please, add commas between --color-white's percentages and after passing the var (before '1' in color). This solution should work:

:root {
 --color-white:  0, 0%, 100%;
}

color: hsla(var(--color-white), 1);

It looks like rgb() works without commas, but hsla() needs commas. See here: http://codepen.io/Aleksgrunwald/pen/abpQQrr

2 Comments

Commas are not needed in hsl() or hsla() for newer browsers.
hmm.. I checked in two online editors (Codepen) and rgb() works without commas, but hsla() needs commas. codepen.io/Aleksgrunwald/pen/abpQQrr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.