question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS3 calc() function doesn't work with LESS

See original GitHub issue

I know it’s been reported already but bugs were closed due to insufficient information.

I have the following CSS code:

#id1 {
    position: fixed;
    left: 0; top: 0;
    width: 130px;
}
#id2 {
    position: fixed;
    right: 0; top: 0;
    width: calc(100% - 130px);
}

I wanted to transform it into LESS using 130px as a parameter but calc gets internpreted by LESS and this:

@id1width: 130px
#id1 {
    position: fixed;
    left: 0; top: 0;
    width: @id1width;
}
#id2 {
    position: fixed;
    right: 0; top: 0;
    width: calc(100% - @id1width);
}

makes the last but one line transformed to width: calc(-30%); which is clearly not what’s desired. I tried using width: ~"calc(100% - @id1width)"; but it makes @id1width not interpreted.

I think LESS shouldn’t use things reserved by CSS3 for its internal use…

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Reactions:19
  • Comments:51 (21 by maintainers)

github_iconTop GitHub Comments

77reactions
lukeapagecommented, Oct 8, 2012

they were probably closed as duplicates… though I can’t find one about calc… see #146 #122 and #915

workaround: width: ~"calc(100% - @{id1width})"; - note curly brackets around variable.

We are moving to a system where only things inside brackets will be evaluated to fix this problem.

23reactions
aamirshahzadcommented, Sep 5, 2014

height: ~“calc(100% - 50px)”; Worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable LESS-CSS Overwriting calc() - Stack Overflow
This works as Less concatenates values (the escaped strings and math ... note that Strict Math is applied globally, not only inside calc()...
Read more >
CSS3 calc() in LESS CSS (Example) - Coderwall
Today I was banging my head that CSS3 calc() property was not working correctly in any browsers. Then I realized I am using...
Read more >
A Complete Guide to calc() in CSS
CSS has a special calc() function for doing basic math. In this guide, let's cover just about everything there is to know about...
Read more >
calc() - CSS: Cascading Style Sheets - MDN Web Docs
The calc() CSS function lets you perform calculations when specifying CSS property values. It can be used with , , , , ,...
Read more >
Using The CSS Function calc() Inside The LESS CSS ...
However, when I went to use it, I didn't get the expected value. calc() appears to conflict with a built-in function inside of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found