CSS SCSS (sass) 计算:#{}

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11783451/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 04:40:17  来源:igfitidea点击:

SCSS (sass) calculation: #{}

csssass

提问by matt

i'm quite confused at the moment when it comes to calculating a font-size

在计算字体大小时,我现在很困惑

this is the normal calculation I already use.

这是我已经使用的正常计算。

font-size: #{($font-size*0.7) / $em}em

font-size: #{($font-size*0.7) / $em}em

What I wanna do now is divide an entire statement like the one above with another one …?sounds complicated I know.

我现在想要做的是将一个完整的陈述(如上面的陈述)与另一个陈述分开......?我知道听起来很复杂。

So I have #{($font-size*0.7) / $em}And I have #{($font-size*0.8125) / $em}

所以我有#{($font-size*0.7) / $em}我有#{($font-size*0.8125) / $em}

I want to devide those two values now …

我现在想分开这两个值......

So font-size: #{($font-size*0.7) / $em} / #{($font-size*0.8125) / $em}em.

所以font-size: #{($font-size*0.7) / $em} / #{($font-size*0.8125) / $em}em

But that doesn't work. Any idea how I do a calculation like that with SASS?

但这不起作用。知道我如何用 SASS 做这样的计算吗?

回答by ScottS

Try:

尝试:

font-size: #{(($font-size*0.7) / $em) / (($font-size*0.8125) / $em)}em

The interpolation back into a string #{...}should be the last thing done after the calculations.

插回字符串#{...}应该是计算后做的最后一件事。

回答by o.v.

ScottS answer appears to be technicallycorrect, but why do you even need such a complex expression in the first place? Expressed as a fraction, this can be simplified to

ScottS 的答案在技术上似乎是正确的,但是为什么您首先需要如此复杂的表达式?表示为分数,这可以简化为

($font-size * 0.7 / $em) / ($font-size * 0.8125 / $em) = 0.7 / 0.8125

And your final expression would be

你的最终表达是

font-size: #{(0.7/0.8125)}em

...wouldn't it?

……不会吧?