【问题标题】:In Sass, how can I output a % sign [duplicate]在 Sass 中,如何输出 % 符号 [重复]
【发布时间】:2016-03-25 16:01:10
【问题描述】:

我正在尝试使用 for 循环创建一系列 CSS 选择器:

@for $i from 1 through 3 {
  .bottom-#{$i} {
    bottom: #{$i}%;
  }
}

我想要一个如下所示的输出:

.bottom-1 { bottom: 1%  }
.bottom-2 { bottom: 2%  }
.bottom-3 { bottom: 3%  }

但 SASS 不喜欢 % 符号 - 它正在尝试评估语句。我假设有办法逃脱这样的角色,但我找不到它。

有什么想法吗?

谢谢

【问题讨论】:

  • @cimmanon 你能告诉我如何使用重复问题中使用的技术获得我所指示的输出吗?这似乎是不可能的。

标签: sass


【解决方案1】:

您可以使用percentage()函数将数字转换为百分比,然后除以100

@for $i from 1 through 3 {
  .bottom-#{$i} {
    bottom: percentage($i / 100);
  }
}

【讨论】:

  • 谢谢 - 我没有意识到百分比函数实际上会在字符串上呈现一个 '%' 符号。
猜你喜欢
  • 2010-12-21
  • 1970-01-01
  • 1970-01-01
  • 2016-06-25
  • 1970-01-01
  • 2014-12-10
  • 2020-04-01
  • 2021-01-11
  • 2023-02-05
相关资源
最近更新 更多