【问题标题】:SASS::Script::Color not being interpreted as a color by some SASS functionsSASS::Script::Color 未被某些 SASS 函数解释为颜色
【发布时间】:2013-09-17 20:00:19
【问题描述】:

我最近决定要在编译我的 SASS 时运行一些默认操作,并发现这个堆栈溢出问题帮助我编写了一个函数来执行此操作 (Use variable defined in config.rb in scss files)

颜色值被很好地拉出并被视为 SASS 颜色对象(即,如果我将“#ff0000”传递给函数,它会显示为“红色”,这很好)但它在色调中不起作用() 和 shade() 函数。

我得到的错误是

(第 137 行:“#ff1122”不是“阴影”的颜色)

但是如果我注释掉所有 tint() 和 shade() 的实例,那么它就可以完美地工作了。

这是所有正在使用的代码:

config.rb(取自前面提到的堆栈溢出链接)

sass_options = {:custom => { :custom_colors => {"main" => "#ff1122"} } }

module Sass::Script::Functions
  def custom_color(value)
    rgb = options[:custom][:custom_colors][value.to_s].scan(/^#?(..?)(..?)(..?)$/).first.map {|a| a.ljust(2, a).to_i(16)}
    Sass::Script::Color.new(rgb)
  end
end

style.scss(第 5 行)

$col_primary : #{custom_color(main)};

style.scss(错误中提到的第 137 行)

@include background-with-css2-fallback(linear-gradient(-45deg, transparent 51%, shade($col_primary, 10) 50%, $col_primary 75%, $col_primary 0%));

我看不出这不起作用的原因,因为它在其他地方用作颜色。

如果需要,我可以提供更多信息

【问题讨论】:

  • 如果没有真正的解决方案,您可以使用 mix 代替 tint/shade,因为所有这些功能真正做的就是将指定的颜色与白色/黑色混合。
  • 我在使用 mix 时遇到同样的错误 - 我想这是有道理的,因为它可能只是在内部使用该函数

标签: sass compass-sass


【解决方案1】:

我的问题最终变成了这个

$col_primary : #{custom_color(main)};

我从示例中提取的内容 - 我认为 SASS 将其解释为字符串,因此函数返回正确的类型并不重要。

【讨论】:

    猜你喜欢
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多