knyxs
knyxs

Reputation: 3

Problems with Calc in Less

I try to define a variable to get dynamic height and do some operations on it; But the code failed to compile. How can I deal with the problem? Thanks.

"less": "3.9.0",

@block-height: calc(~"(100vh - 110px) / 3");
.block1{
  height: @block-height - 100
}
.block2{
  height: @block-height * 2
}

Upvotes: 0

Views: 360

Answers (1)

JasonB
JasonB

Reputation: 6368

You may need to move the calc from your variable to the places you are using it, and escape the operators. Using https://lesstester.com/ to do a quick test, the following less source code

@block-height: ~"(100vh - 110px) / 3"; 

.block1{ height: calc( @block-height ~"-" 100 ); } 
.block2{ height: calc( @block-height ~"*" 2); }

becomes this when parsed

.block1 {
    height: calc((100vh - 110px) / 3 - 100);
}
.block2 {
    height: calc((100vh - 110px) / 3 * 2);
}

Upvotes: 1

Related Questions