How to use Calc in the less framework

Source: Internet
Author: User
Tags diff

The benefits of the

Less needless to say, everyone knows that it does not hurt to write CSS, and I did find some problems when I joined Calc recently in less, which I wrote in less:
Div {
 width:calc (100%-30px);

The result less this as an expression, and the result is resolved to me as follows:
Div {
  width:calc (70%);
}
So, I rewrite less to this:
Div {
 width:calc (~ "100%-30px");
}
The parse result is normal:
Div {
  width:calc (100%-30px);
}
However, instead of replacing 30px with a variable, how do I write it?
Div {
  @diff: 30px;
 width:calc (~ "100%-" + @diff);
}
This write Webstorm no error, but grunt-less error:
C:\users\zhong\webstormprojects\test>grunt less
Running "less: Development "(less) task
>> parseerror:unrecognised input in style.less on line 4, column 2:
>> 3&nbs p;   @diff: 30px;
>> 4    Width:calc (~ "100%-" + @diff);
>> 5}
Warning:error compiling style.less use--force to continue.

Aborted due to warnings.
So write:
div {
@diff: 30px;
Width:calc (~ "100%-" @diff);
}
The successful compilation of the past, but Webstorm is always prompted syntax errors, although also can compile but look at the file has a wrong hint heart old feeling bad, find half day also didn't find webstorm how to debug syntax prompts error settings

So, change to the following wording:
div {
@diff: 30px;
Width:calc (~ "100%-@{diff}");
}
This kind of writing can compile again, webstorm not error, so I prefer to use this writing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.