1

Can I use classes to change CSS variables in SCSS file? it works but I want to know if it's the right way to do it:

.header {
  --transform: translate(-50%, 0);
  transform: var(--transform);
  &--hide {
     --transform: translate(-50%, -84px);
  }
  &--show {
     --transform: translate(-50%, 0);
  }
}

// instead of this:

.header {
  transform: translate(-50%, 0);
  &--hide {
     transform: translate(-50%, -84px);
  }
  &--show {
     transform: translate(-50%, 0);
  }
}
1
  • thank you for your answer. I tried it and it works, I'm using it for a navbar animation when I scroll up the navbar slide down Commented Apr 9, 2022 at 15:57

1 Answer 1

2

Yes you override in your class the css variable like that:

:root {
  --test: red;
}    
.header {    
  --test: green;
  color: var(--test);       
}
<div class="header">abc</div>

Note:: But I can't imagine a use case right now!?

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

1 Comment

thank you. I'm using it for a navbar animation when I scroll up the navbar slide down

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.