Home > Web Front-end > CSS Tutorial > How Can I Prevent LESS CSS from Modifying `calc()` Expressions?

How Can I Prevent LESS CSS from Modifying `calc()` Expressions?

DDD
Release: 2024-12-07 22:54:17
Original
337 people have browsed it

How Can I Prevent LESS CSS from Modifying `calc()` Expressions?

Overcoming LESS CSS Calc() Compilation Issue

In an attempt to utilize calc() within LESS code, developers may encounter an issue where the LESS compiler alters the calculation, resulting in incorrect output. For instance, the following code:

width: calc(100% - 200px);
Copy after login

renders as:

width: calc(-100%);
Copy after login

To resolve this, one can employ escaped strings within LESS. This approach allows the calc() expression to be treated as a string, preventing the compiler from manipulating it.

width: ~"calc(100% - 200px)";
Copy after login

This ensures that the final output remains consistent with the original code. Additionally, it is possible to combine Less math with escaped strings, as demonstrated below:

width: calc(~"100% - 15rem +" (10px+5px) ~"+ 2em");
Copy after login

This will compile to:

width: calc(100% - 15rem + 15px + 2em);
Copy after login

Less concatenates values with a space by default, enabling the seamless integration of escaped strings and calculation results. Implementing this technique effectively disables LESS's overwriting of calc() expressions.

The above is the detailed content of How Can I Prevent LESS CSS from Modifying `calc()` Expressions?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template