【问题标题】:how do I add a % to my SASS calculation?如何在我的 SASS 计算中添加 %?
【发布时间】:2012-08-20 22:11:39
【问题描述】:

我使用 SASS 根据元素宽度和容器宽度将宽度尺寸转换为 %,但是我的问题是,如果我在计算的末尾添加 % 会出现错误,谁能告诉我如何解决这个问题?

@mixin percentageWidth( $elementWidth, $containerWidth ){
  width: (($elementWidth/$containerWidth)*100) + %;
  *width: ((($elementWidth/$containerWidth)*100) - ((0.5/$containerWidth)*100)) + %;
}

【问题讨论】:

  • 您不需要所有这些括号。 a/b*c 代替 ((a/b)*c)a/b*c-d/e*f 代替 (((a/b)*c)-((d/e)*f))
  • 谢谢,我怎样才能更新这个 mixin 以便我可以使用不同的属性,如 margin-right 或 width 或 padding?

标签: css sass


【解决方案1】:

根据the documentation,您需要将结果乘以100%,而不是像字符串一样尝试添加%

width: ($elementWidth/$containerWidth) * 100%;
*width: (($elementWidth/$containerWidth) - (0.5/$containerWidth)) * 100%;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-17
    • 2015-11-14
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多