在Sass中乘以百分比 [英] Multiply percentages in Sass

查看:94
本文介绍了在Sass中乘以百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何以一种明智的方式在Sass中将两个百分比相乘?

How do I multiply two percentages together in Sass, in a sensible way?

例如,考虑以下声明:

$num1: 50%;
$num2: 25%;
$num3: $num2 * $num1; 

在这里,num3中断.我可以写什么表达式将num3定义为12.5%?

Here, num3 breaks. What expression can I write to have num3 defined as 12.5%?

推荐答案

弄清楚了;首先,您需要将百分比之一转换为小数.这是完成的方式:

Figured it out; first you need to convert one of the percentages to a decimal. Here's how it's done:

$num1: 50%;
$num2: 25%;
$num3: ($num2/100%) * $num1;

这篇关于在Sass中乘以百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆