matthiasmullie / minify

CSS & JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.
https://matthiasmullie.github.io/minify/
MIT License
1.96k stars 310 forks source link

Problem with units #384

Closed picov closed 2 years ago

picov commented 2 years ago

:root{--uk-position-margin-offset:0px}

is minified as

:root{--uk-position-margin-offset:0}

and this cause bad CSS behaviour

felipemarcos commented 2 years ago

We shouldn't minify 0px as 0 in CSS variables. Unitless 0 as length won't work in calc() and other math functions. Source

Specification Note: Because number-tokens are always interpreted as numbers or integers, "unitless 0" lengths aren’t supported in math functions. That is, width: calc(0 + 5px); is invalid, because it’s trying to add a number to a length, even though both width: 0; and width: 5px; are valid.

Demo

--column-gap: 0px;
width: calc(100% - var(--column-gap));
obedparla commented 2 years ago

We have a fork of this and fixed it by removing the shortenZeroes function in CSS.php. We didn't find much value in removing a few zeroes at the cost of the complexity. A proper solution would need some more regexes.

RV7PR commented 2 years ago

Fixed in #392