TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

CSS calc(100% – 0) is invalid, but calc(100% - 0px) is valid

40 pointsby mrzoolover 2 years ago

9 comments

zarzavatover 2 years ago
Since many people apparently didn’t read TFA, the issue is that when you have an expression such as calc(100% - var(—-x)), it is invalid if var(—-x) is 0 with no units, which is otherwise valid in CSS. This is clearly a bug in the spec.
评论 #32914605 未加载
评论 #32912086 未加载
bilekasover 2 years ago
To be honest this isn&#x27;t that strange, the parser needs to know what denomination you&#x27;re trying to subtract.. Also as per the spec the `-` operand requires a whitespace. So it&#x27;s not actually valid to use (100&amp; -0) you&#x27;re getting a false positive..<p><a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;CSS&#x2F;calc#notes" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;CSS&#x2F;calc#notes</a>
评论 #32910549 未加载
评论 #32910297 未加载
croesover 2 years ago
From MDN<p>&quot;For lengths, you can&#x27;t use 0 to mean 0px (or another length unit); instead, you must use the version with the unit: margin-top: calc(0px + 20px); is valid, while margin-top: calc(0 + 20px); is invalid.&quot;<p><a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;CSS&#x2F;calc?retiredLocale=de" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;CSS&#x2F;calc?retire...</a>
compressedgasover 2 years ago
Indirect post of <a href="https:&#x2F;&#x2F;www.oddbird.net&#x2F;2022&#x2F;08&#x2F;04&#x2F;zero-units&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.oddbird.net&#x2F;2022&#x2F;08&#x2F;04&#x2F;zero-units&#x2F;</a>
seba_dos1over 2 years ago
This is something that, if you have any experience with CSS, seems confusing for a few seconds but then simply makes perfect sense.
beardywover 2 years ago
I am a great proponent of the unitless zero pretty much everywhere. I am pleased CSS supports it. An empty chicken shed is just a shed.<p>Sadly here it does force a special case where it either becomes a nop or it adopts the units required. Not sure which is best.
leephillipsover 2 years ago
Maybe CSS is evolving toward TeX?
mike_tempestover 2 years ago
This is obvious why it is invalid, 0 doesn&#x27;t have an associated unit so the compiler doesn&#x27;t understand.
评论 #32913690 未加载
radoover 2 years ago
Had this issue on Safari only, not Chrome. I wish browsers would fix the basics before taking on ambitious new features.
评论 #32910867 未加载
评论 #32910401 未加载