Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The value of opacity in less was been modified by cssnano if I specificied the value in percent form #829

Closed
yanyu0517 opened this issue Oct 28, 2019 · 6 comments
Labels

Comments

@yanyu0517
Copy link

yanyu0517 commented Oct 28, 2019

I had declared the opacity in percent form that maybe not a standard, and got the modification of value after processed by cssnano. Just like below picture

image

98% changed to 1%

@yanyu0517 yanyu0517 changed the title The value of opacity in less was been modified by cssnano if I The value of opacity in less was been modified by cssnano if I specificied the value in percent form Oct 28, 2019
@yanyu0517
Copy link
Author

The reason for this issue has been located by my workmate.
The 55th line of cssnano/packages/postcss-convert-values/src/index.js
is the point. If the opacity is declared in percent form like 98%, the content of pair object may like this:

{
    number: 98,
    unit: '%',
}

pair.number is greater than 1 and the node.value would be assigned 1%

@anikethsaha
Copy link
Member

seems like a bug. it should be

if a number is greater than 1
then it should be converted to a percentage of 1

like (number/100) * 1

opacities range from 0-1 so if the number is greater than one. convert it with respect to 1.

or even if we can do with respect to the unit. if it's mentioned as % then simply pass it as it is. no need for any conversion the browser will take care of it.

@alexander-akait
Copy link
Member

@anikethsaha feel free to send a PR with fix

@alexander-akait
Copy link
Member

It is invalid syntax, please fix your code, invalid syntax is not allowed for minification

@redeyes2015
Copy link

Just in case anyone like me bumping into this issue in the future: #881 have fixed this, but there is no release including it, yet, as of 2020/4/20. For now, if you need cssnano, replace the percentage syntax is the easiest option.

In CSS color 3, percentage for opacity is allowed, but CSS color 4 will make this sytnax (opacity: 98%) valid:

And Chrome and Firefox seem to support it already; a short experiment also shows they do support percentage syntax of opacity.

@parzibyte
Copy link

Well, just to clarify. If you are specifying the opacity in percentage like this:

img{
opacity: 70%;
}

Change it to:

img{
opacity: 0.7;
}

And it will work like a charm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants