1

I have in css (generated by sass) variable called --secondary and it's value is red(#f00)
I want to create more variables for opacity like --secondary-100, --secondary-90, ...
I used color-mix in oklab, so this is the code:

setTimeout(_ => {
  document.querySelector('div').style.cssText += `--secondary:#f00;`
},100)
div { 
  width:100px;
  height:100px;

  --secondary-100: color-mix(in oklab, var(--secondary) 100%, transparent 0%);
  background-color: var(--secondary-100);
}
<div></div>

as you can see the div is transparent not red ( if you see it red that mean i didn't recreate the problem the problem stile exist in the real firefox site ) i tried it in firefox and this is the result enter image description here enter image description here

in devtools i just wrote the same thing contains in the variable --secondary-100 out of it and it suddenly works idk where is the problem or is it a well known problem and I'm living under my rock

btw this variables and colors is user choice and not static so i can't just write them my self and the best i can do is to use javascript to deal with those colors and save them directly without using color-mix

6
  • Does this answer your question? How to create color shades using CSS variables similar to darken() of Sass? Commented Jun 4, 2024 at 6:21
  • no i doesn't because the javascript changes the colors so i just use normal css variables not compiled with sass Commented Jun 4, 2024 at 7:01
  • The top answer is a CSS-only solution. Unsure where you're seeing SASS ? Commented Jun 4, 2024 at 7:09
  • no the same problem it works if i right it as a value to the background property directly but if it's inside another variable it doesn't work for some reason but good suggestion Commented Jun 4, 2024 at 7:20
  • it was new to me as if it's a magic so i assumed it was something to do with sass Commented Jun 4, 2024 at 7:20

2 Answers 2

0

You have to specify the method parameter. It is the first parameter.

div {
  width: 100px;
  height: 100px;
  --secondary: #f00;
  --secondary-100: color-mix(in srgb, var(--secondary) 100%, transparent 0%);
  background-color: var(--secondary-100);
}
<div></div>

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

1 Comment

i just forget it in this code example but i didn't work
0

It just worked when I replaced the :root with *. I don’t know why or how, but in Chrome dev tools, it appears that the variable declared in the :root wasn't declared in the children.

Comments

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.