Home >Web Front-end >CSS Tutorial >How Can I Avoid Less Compiler Errors When Using CSS `calc()` Properties?

How Can I Avoid Less Compiler Errors When Using CSS `calc()` Properties?

DDD
DDDOriginal
2025-01-02 19:51:40631browse

How Can I Avoid Less Compiler Errors When Using CSS `calc()` Properties?

Less Compiler Misinterpreting CSS calc() Properties

Certain Less compilers, including OrangeBits and dotless, incorrectly convert CSS calc() expressions. For instance, the expression "width: calc(100% - 250px - 1.5em)" is mistakenly transformed into "width: calc(-151.5%)".

Solution in Less 3.00 and Later

In Less versions 3.00 and above, the compiler no longer automatically evaluates expressions within calc(). This change eliminates the need for manual intervention when using calc().

Solution in Earlier Less Versions

For Less versions below 3.00, users can prevent automatic evaluation by enclosing the calc() expression within the ~ operator. For example:

body { width: calc(~"100% - 250px - 1.5em"); }

Additionally, Less version 1.4.0 introduced a strictMaths option, which requires all Less calculations to be enclosed in parentheses. This option ensures that calc() expressions are handled correctly by default.

The above is the detailed content of How Can I Avoid Less Compiler Errors When Using CSS `calc()` Properties?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn