1

I have a CSS variable called --menuWidth. I'm trying to use this variable with an arithmetic operator but I'm having trouble.

I tried the following:

left: calc(var(--menuWidth) + 20px);

But the less processor output says "OperationError: Operation on an invalid type" (at column 2?)

I found this working codepen which actually seems to confirm the syntax above, so I'm assuming this is a LESS issue. If so, how can I fix it?


Here is my file structure:

vars.less

:root {
    --menuWidth: 200px;
}

@media screen and (min-width: 1280px) and (max-width: 1919px){
    :root {
        --menuWidth: 250px;
    }
}
@media screen and (min-width: 1920px){
    :root {
        --menuWidth: 300px;
    }
}

layout.less

#headerContainer {
    left: calc(var(--menuWidth) + 20px);
}

compiled.less

@import "vars.less";
@import "layout.less";

1 Answers1

1

Updating LESS from 2.7.2 to 3.0.4 fixed the issue.