CSS calc()不工作

前端之家收集整理的这篇文章主要介绍了CSS calc()不工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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 of calc(50% -8px) for instance will be parsed as a percentage
followed by a negative length,an invalid expression,while the
operand of calc(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.

把你的东西放在一边,这可能会起作用.

猜你在找的CSS相关文章