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

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

Patricia Arquette
Release: 2024-12-24 19:37:10
Original
167 people have browsed it

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

Preventing Less Compiler from Manipulating CSS calc() Properties

In an attempt to prevent Less compilers from translating CSS calc() properties into undesired values, it is important to understand their behavior. Less compilers interpret calc() expressions and perform mathematical operations, leading to unexpected results in certain scenarios.

Less Compiler Configuration

Less no longer evaluates expressions inside calc() by default since version 3.00. To prevent this transformation, ensure you are using the latest version of Less.

Option for Older Less Versions

For older versions of Less (v1.x...2.x), enclose calc() expressions within tilde (~) characters. This signals to the compiler to treat the expression as a string and prevent evaluation:

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

Less Configuration

Less 1.4.0 introduces the strictMaths option, which requires all Less calculations to be within brackets. With this option enabled, calc() expressions will work out-of-the-box without the need for tilde characters. However, note that this option may cause breaking changes in existing code.

The above is the detailed content of How Can I Prevent Less Compilers from Modifying 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