Nested calc with css variables
See original GitHub issuethanks @evilebottnawi for redirection. #816
I’m encountering an issues while using calc() with CSS Custom variables where presets automatically remove my nested calc while custom variables is unable to resolve in build time.
Given that:
body {
top: calc(100% - calc(10px + 10px));
}
/* will compile to*/
body {
top: calc(100% - 20px);
}
when it comes to a css variables
body {
top: calc(var(--pic-height) - calc(var(--width-height) + var(--border-gap)));
}
/* will compile to*/
body {
top: calc(var(--pic-height) - var(--width-height) + var(--border-gap));
}
which is incorrect in mathematical stand points. To solve this problem, I end up by setting calc preset to false in plugin options.
Is there any possible to omit any clearing unintended nested calc while encountering css variable or if there is any better solution while dealing with variables value?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:5
Top Results From Across the Web
calc() function inside another calc() in CSS - Stack Overflow
It is possible to use calc() inside another calc(). An example: div{ width: calc(100% - (1% + 30px));/* calc(1% + 30px) is nested...
Read more >calc() - CSS: Cascading Style Sheets - MDN Web Docs
The calc() CSS function lets you perform calculations when specifying CSS property values. It can be used with <length> , <frequency> ...
Read more >A Complete Guide to calc() in CSS
calc () is a native CSS way to do simple math right in CSS as a replacement for any length value (or pretty...
Read more >How and when to use CSS calc(): Tutorial with examples
The calc() function allows you to perform computations when specifying CSS property values. It's especially useful for calculating length, ...
Read more >CSS: nested calc() for Custom Properties - CodePen
CSS: nested calc() for Custom Properties. (margin-top for vertical aligning). CSS variable is defined using calc();; Another variable/property is defined ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I raised an issue on cssnano (https://github.com/cssnano/cssnano/issues/628) but believe the issue lies upstream from there in this repo.
I am able to reproduce the same behavior, that the following two CSS styles produce different outputs (confirmed in Chrome 80 and Firefox 74 on Mac OS 10.15.3):
Computed:
padding-bottom: 276.906px
(correct)Computed:
padding-bottom: 0px
(incorrect)I’m not sure why the parentheses matter in this situation, but the empirical evidence suggests they do. I suggest therefore the parentheses should not be removed.
So the first issue is already fixed in 8.2, while the issue in https://github.com/postcss/postcss-calc/issues/91#issuecomment-605059796 is a duplicate of #113