CSS Calc() 函数要求在 “+” 或 “-” 运算符前后都需要空格。

huangapple go评论59阅读模式
英文:

why does CSS Calc() function requires whitespaces before and after "+"or "-" operators ONLY

问题

calc(10px + 2px); 正确
但是
calc(10px +2px); 会出错
或者
calc(10px - 2px); 正确
但是
calc(10px -2px); 会出错。然而,这不适用于其他运算符。

英文:

Ex:calc(10px + 2px); is correct
but
calc(10px +2px); gives out an error
or
calc(10px - 2px); is correct
but
calc(10px -2px); gives out an error. However, this doesn't apply to other operators

答案1

得分: 6

对于+运算符,操作可能会比calc(10px + 2px);更复杂一些。我的意思是像calc(5px + -1px);这样的东西实际上更复杂,而且不能是calc(5px+-1px);

对于-运算符,CSS应该如何知道-是减号运算符还是负数的一部分?我是指从逻辑上来说。

此外,空格使代码更容易阅读,对于人类来说很重要。

在文档中了解更多关于CSS calc() 函数的信息。

英文:

For the + operator, the operation might get a little more complicated than calc(10px + 2px);. I mean something like calc(5px + -1px); is actually more complicated, and it can't be calc(5px+-1px);.

For the - operator, how CSS is supposed to know whether the - is the minus operator or a part of a negative number? I mean logically though.

Also, the whitespaces make the code nice to read, for humans.

Learn more about the CSS calc() function in the documentation.

huangapple
  • 本文由 发表于 2023年7月24日 00:51:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76749372.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定