CSS calc()函数中可以有多少操作数有限制?
这样做:
div { left:calc((100%/54)*26); left:-webkit-calc((100%/54)*26); }
这不工作:
div { left:calc(((100%/54)*14)-140px); left:-webkit-calc(((100%/54)*14)-140px); }
当然,后者是我需要的,因为我需要偏移几个像素,但是一旦我尝试这样做,这个值似乎只是零.任何见解都不胜感激!
解决方法
引用
MDN
The
+
and-
operators must always be surrounded by whitespace. The
operand ofcalc(50% -8px)
for instance will be parsed as a percentage
followed by a negative length,an invalid expression,while the
operand ofcalc(50% - 8px)
is a percentage followed by a minus sign
and a length. The*
and/
operators do not require whitespace,but
adding it for consistency is allowed,and recommended.
把你的东西放在一边,这可能会起作用.