Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use native CSS min/max functions with LESS [duplicate]

Tags:

css

less

I want to use the min() CSS function with a stylesheet written in LESS. However, LESS has its own min and max functions that precompute values (making it impossible to mix-and-match units). How do I get it so the output CSS has the min/max functions as I wrote them?

Here is the style in the LESS file, which should also be the expected output.

canvas {
    background: white;
    width: min(95vh, 95vw);
    height: min(95vh, 95vw);
}

I am using lessc 3.13.1, which produces the following error:

ArgumentError: error evaluating function `min`: incompatible types in <snipped> on line 49, column 12:
48     background: white;
49     width: min(95vh, 95vw);
50     height: min(95vh, 95vw);
like image 379
MiffTheFox Avatar asked Jun 15 '26 23:06

MiffTheFox


1 Answers

Use LESS' string escaping capabilities to pass along a plain string to the CSS.

canvas {
    background: white;
    width: ~"min(95vh, 95vw)";  
    height: ~"min(95vh, 95vw)"; 
}

See Also: Less doesn't support new math functions (e.g. min, max) #3463

like image 164
mahan Avatar answered Jun 22 '26 08:06

mahan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!