【问题标题】:Why is the scss repeat function not working? [duplicate]为什么 scss 重复功能不起作用? [复制]
【发布时间】:2019-02-10 03:56:43
【问题描述】:

我想在 scss 中做到这一点border-color: rgb(170, 170, 170) repeat(3,black) ;

而不是border-color: rgb(170, 170, 170) black black black ;

但是当我查看css文件时,我发现scss将它编译为

border-color: rgb(170, 170, 170) repeat(3,black) ;

所有其他功能都运行良好( lighten() ,darken() ... )。

对这个问题有任何想法吗?通常它应该可以工作

【问题讨论】:

  • @DogukanCavus 我在 post 解决方案中使用了类似 montionned 的函数指令,但我仍然不明白为什么这个特定函数不起作用,而其他所有函数都不起作用。
  • 重复函数是SASS的内置函数吗?
  • 是的,这不是我第一次使用它。编辑:我刚刚去了官方sass页面,但没有找到repeat()函数,我现在真的很困惑。
  • 我认为 sass 中没有任何内置的 repeat() 函数。必须创建一个。
  • 我想我只是不知何故感到困惑,答案中的代码对我来说非常有效,因为我只想重复属性值,而不是文本。

标签: css sass compilation


【解决方案1】:

这是一个可以完成这项工作的 SASS 函数。

@function repeater($n, $character) {
    $c: "";

    @for $i from 1 through $n {
        $c: $c +" "+ $character;
    }

    @return unquote($c);
}

// now i can use it :D
border-color: rgb(170, 170, 170) repeater(3, black);

【讨论】:

  • 那么你确认复制了吗?
  • 我确认了,但我使用了 unquote() 函数,以便我可以在属性值而不是文本上使用它。
猜你喜欢
  • 2018-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-22
相关资源
最近更新 更多