2

I'd need to darken a color specified in a CSS variable.

I have this CSS code:

background:linear-gradient(to right, 
                           var(--mainContainer-background) 80%,
                           @gray-light 100%);

CSS variable --mainContainer-background can be changed by user on-the-fly with a bit of JS, but I'd want to set a darken variation of this color in my background gradient, for example I'd want that gradient start from a color that is 20% darker of one stored in --mainContainer-background.

Is possible in some way?

1 Answer 1

2

You may consider another gradient above with a transparent black color:

.box {
  min-height:50px;
  margin:20px;
  background: 
   linear-gradient(to right,rgba(0,0,0,0.6),transparent 80%),
   linear-gradient(to right, var(--color,blue) 80%, grey 100%);
}
<div class="box" style="--color:red;">
</div>
<div class="box" style="--color:pink;">
</div>
<div class="box" >
</div>

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

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.