CSS calc() 不工作

标签 css

<分区>

在一个 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 calc() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14967421/

相关文章:

javascript - 无法更改 js 中的文本,类文本

css - Angular animate帮助——滑动然后隐藏

javascript - 加载后自动点击页面上的链接,基于之前的链接

css - 多次将相同的 css 应用于一个元素

javascript - 我需要在 gwt 中的复选框和复选框名称之间留一个空隙

html - CSS 中的已访问链接

javascript - 某些东西导致这个 CSS 崩溃

html - Markdown 段落之间三个省略号

html - 将 z-index 应用于 :pseudo element

jquery - slider 内容被推出容器