Home > Web Front-end > CSS Tutorial > How Can I Prevent Less Compilers from Incorrectly Evaluating CSS `calc()` Properties?

How Can I Prevent Less Compilers from Incorrectly Evaluating CSS `calc()` Properties?

Mary-Kate Olsen
Release: 2024-12-30 00:31:18
Original
375 people have browsed it

How Can I Prevent Less Compilers from Incorrectly Evaluating CSS `calc()` Properties?

Less and CSS Calc() Properties: Hindering Aggressive Compilation

Less compilers, such as OrangeBits and dotless, may attempt to compile and evaluate CSS calc() properties, leading to incorrect results. This article explores ways to prevent this behavior and maintain desired CSS styles.

Less's Default Behavior

Less used to proactively evaluate expressions within calc(), resulting in erroneous outcomes. For instance, body { width: calc(100% - 250px - 1.5em); } would be incorrectly translated to body { width: calc(-151.5%); }.

Solution for Less

Do this:

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

By using the ~ operator, you signal to Less to ignore the expression during compilation.

Solution for Less v3.00 and Later

Less no longer automatically evaluates expressions within calc() by default. Therefore, for Less v3.00 and later, no specific actions are necessary to prevent aggressive compilation.

Strict Maths Option

In Less 1.4.0, there is a strictMaths option that requires all Less calculations to be enclosed in brackets. This option ensures that calc() will work as intended without any modifications. By default, this option is turned off in the release version of Less 1.4.0.

The above is the detailed content of How Can I Prevent Less Compilers from Incorrectly Evaluating CSS `calc()` Properties?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template