1

I am trying the following, in order to have the header's height subtracted from the element below it.

header {
  height: var(--header-height);

  --header-height: 150px;
}

main {
  height: calc(100% - var(--header-height));
}

What am I doing wrong?

Why isn't it calculating the "150px" value inside the calc()?

  • Because it doesn't. It displays the "property" you set which is the variable. Are you saying that this calc doesn't work? – Paulie_D Jul 15 '21 at 12:35
  • Yes, the issue was that the calc() didn't load the variable I wanted to use in the equation. But when I moved the declaration of the variable to :root{}, it worked. – Michel Mendez Jul 16 '21 at 12:50

1 Answers1

0

I moved the declaration of the variable to this:

:root {
  --header-height: 200px;
}

Now it works!

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140