英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论