【发布时间】:2017-08-24 13:40:19
【问题描述】:
我有一个 SASS 混合。目前 $line-height 需要是完整的 数字是 1、2 等,但不是 1.4、2.2 等。
@mixin text-style($line-height) {
line-height: $line-height rem;
}
我需要扩展它,这样您就不必使用整数。但为了做到这一点,我需要添加填充以保持垂直节奏。填充值是 $line-height 和下一个整数之间的差。
因此,如果 $line-height 为 1、2 等,则不添加任何填充。
如果 $line-height 为 1.5,则需要添加 0.5 填充。
如果 $line-height 为 1.1,则需要添加 0.9 填充。
SASS 可以做到这一点吗?
【问题讨论】:
-
SASS 知道 floor/ceil 等数学函数,sass-lang.com/documentation/Sass/Script/Functions.html
-
... 使用这些函数,您可以像这样计算差异
$padding: ceil($line-height) - $line-height;
标签: sass