Skip to content

unitless zero value bug #7

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

Closed
yksht opened this issue Oct 21, 2015 · 5 comments · Fixed by #11
Closed

unitless zero value bug #7

yksht opened this issue Oct 21, 2015 · 5 comments · Fixed by #11

Comments

@yksht
Copy link

yksht commented Oct 21, 2015

Hi :)

I'm using postcss and have following expression:

div {
    width: calc(100% - $width - $margin);
}

and I found strange behavior when try to use zero values:

// $width: 200px;
// $margin: 0; or $margin: 0px; or $margin: 0px;
// output: 
div {
    width: calc(100% - 200px - 0); // this is not valid expression inside 'calc' and browsers don't calculate it
}

but these are valid expressions:

width: calc(100% - 200px - 0px);
width: calc(100% - 200px - 0%);

so my question is: Could you fix this? Or this is a normal behavior?
thank you :)

@MoOx
Copy link
Owner

MoOx commented Oct 21, 2015

Can you try this simple workaround?
width: calc(100% - ($width - $margin));

@MoOx MoOx changed the title zero value bug unitless zero value bug Oct 21, 2015
@yksht
Copy link
Author

yksht commented Oct 21, 2015

this method works, but in this case we will have unexpectable behaviour when use different units ('px' for width and '%' for margin)

@MoOx
Copy link
Owner

MoOx commented Oct 21, 2015

If you have a nice solution, PR is welcome ;)

@yksht
Copy link
Author

yksht commented Oct 21, 2015

ok :) thanks. I will do

@yksht
Copy link
Author

yksht commented Oct 21, 2015

'csswring' plugin remove units for zero values :( 'reduce-css-calc' works perfectly and passes all tests... sorry for disturbing

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

Successfully merging a pull request may close this issue.

2 participants