-1

I need to pass some data to a component to be used in CSS calculations. These calculations will depend upon breakpoints as well. It isn't working and I believe that the issue is that I don't know where to place the "px".

React Side

<MainMenu className={styles.mainMenu} myVar={ref1.current.clientHeight - ref2.current.clientHeight/>

CSS Side

.mainMenu {
   @include breakpoint(xlarge) {
      margin-top: var(--myVar)px;
      height: calc(100vh - var(--myVar)px);
  }
   @include breakpoint(small) {
      margin-top: var(--myVar - 47)px;
      height: calc(100vh - var(--myVar - 47)px);
  }
}
2
  • Try e.g. calc(100vh - (var(--myVar) * 1px)) - assuming myVar does not already have a unit associated with it. Commented Jul 20, 2024 at 18:37
  • look that : stackoverflow.com/questions/52005083/… Commented Jul 20, 2024 at 18:47

1 Answer 1

0

You never set a value for --myVar in your document style.

You also cant write stuff like this var(--myVar)px and this var(--myVar - 47)px

The solution would be in the lines of:

React Side

const myVar = ref1.current.clientHeight - ref2.current.clientHeight;
document.documentElement.style.setProperty('--myVar', `${myVar}px`);

CSS Side

.mainMenu {
    @include breakpoint(xlarge) {
       margin-top: var(--myVar);
       height: calc(100vh - var(--myVar));
   }
    @include breakpoint(small) {
       margin-top: calc(var(--myVar) - 47px);
       height: calc(100vh - var(--myVar) + 47px);
   }
 }
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.