Home >Web Front-end >CSS Tutorial >How Can I Preserve `calc()` Functionality When Using LESS?

How Can I Preserve `calc()` Functionality When Using LESS?

DDD
DDDOriginal
2024-12-07 19:23:16143browse

How Can I Preserve `calc()` Functionality When Using LESS?

Preserving calc() Functionality in LESS

When using calc() function in LESS stylesheets, it faces compilation issues, outputting incorrect results. To resolve this, developers can utilize escaped strings, also known as escaped values.

To preserve the original calc() function, prepend it with a tilde (~) within a string, as demonstrated below:

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

This ensures that LESS interprets calc() as a plain string, preventing it from being modified during compilation.

In scenarios where you need to combine Less math with escaped strings, use the following syntax:

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

This code compiles to:

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

By utilizing escaped strings, developers can ensure that calc() functions are interpreted correctly and output as expected by LESS.

The above is the detailed content of How Can I Preserve `calc()` Functionality When Using LESS?. 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