【问题标题】:Sass Mixin Error for IE specific filters like -ms-filterIE 特定过滤器(如 -ms-filter)的 Sass Mixin 错误
【发布时间】:2011-03-23 00:09:29
【问题描述】:

我正在尝试制作这样的按钮混合:

=default_button(!lighter, !darker) 
  :border= 1px !lighter solid
  :background-color #e3e3e3
  :background= -webkit-gradient(linear, 0 0, 0 100%, from(!lighter), to(!darker)) repeat-x, #d0581e
  :background= -moz-linear-gradient(90deg, !darker, !lighter) repeat-x scroll 0 0 #d0581e
  :filter= progid:DXImageTransform.Microsoft.gradient(startColorstr='!lighter', endColorstr='!darker')
  :-ms-filter= "progid:DXImageTransform.Microsoft.gradient(startColorstr='!lighter', endColorstr='!darker')"
  :zoom 1
  :margin 0 0 0 0
  :width auto
  :padding 2px 14px 2px 14px
  :border-radius 10px
  :-webkit-border-radius 10px
  :-moz-border-radius 10px
  :color #FFF

当我编译 sass 时,我在以 -filter 和 -ms-filter 开头的行出现此错误:

SASS::SyntaxError: Expected rparen token, was single_eq token

我很确定这是我放置 = 的位置,但我不确定如何正确编写它。如果我传递十六进制值而不是!lighter,!darker,它会起作用,因为这样我可以像这样删除 = 符号:

:filter progid:DXImageTransform.Microsoft.gradient(startColorstr='#F89F16', endColorstr='#d0581e')
:-ms-filter "progid:DXImageTransform.Microsoft.gradient(startColorstr='#F89F16', endColorstr='#d0581e')"

【问题讨论】:

    标签: css sass compass-sass blueprint-css


    【解决方案1】:

    这样解决了,但仍在寻找最佳方式的替代建议...

    =default_button(!lighter, !darker) 
      text-shadow= 1px 1px 3px darken(!darker, 8)
      border= 1px !darker solid
      background-color= !lighter
      background= -webkit-gradient(linear, 0 0, 0 100%, from(!lighter), to(!darker)) repeat-x, !darker
      background= -moz-linear-gradient(90deg, !darker, !lighter) repeat-x scroll 0 0 !darker
      -ms-filter = "progid:DXImageTransform.Microsoft.gradient(startColorstr='#{!lighter}', endColorstr='#{!darker}')"
      :zoom 1
      :margin 0 0 0 0
      :width auto
    

    自从这个答案最初发布以来,Sass 的语法已经改变。现代 sass(缩进)语法如下所示:

    =default_button($lighter, $darker) 
      text-shadow: 1px 1px 3px darken($darker, 8)
      border: 1px $darker solid
      background-color: $lighter
      background: -webkit-gradient(linear, 0 0, 0 100%, from($lighter), to($darker)) repeat-x, $darker
      background: -moz-linear-gradient(90deg, $darker, $lighter) repeat-x scroll 0 0 $darker
      -ms-filter: unquote("progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$lighter}', endColorstr='#{$darker}')")
      zoom: 1
      margin: 0 0 0 0
      width: auto
    

    【讨论】:

    • 赞成 #{...} 语法。需要这个让 SASS 替换 SASS 3.1.10 上 MS 渐变过滤器的 startColorstr/endColorstr 参数的变量。也就是说,startColorstr=$foo 不起作用(因为它不会替代 $foo),但 startColorstr=#{$foo} 可以。
    • 谢谢..在此之前我的渐变是蓝色到黑色(即默认)哈哈..再次感谢
    • 如果您的颜色具有 alpha 透明度 (rgba),则此方法将不起作用。您需要在下方使用Matthias Dailey's answer
    【解决方案2】:

    插值#{} 有时不起作用,因为它会缩短十六进制颜色值。例如,它将#334455 缩短为#345,这会破坏过滤器语法。

    SASS 3.2 版本新增功能:ie-hex-str()

    这是我如何让它工作的:

    filter: unquote("progid:DXImageTransform.Microsoft.gradient(startColorstr='")
    + ie-hex-str($start)
    + unquote("', endColorstr='")
    + ie-hex-str($stop)
    + unquote("',GradientType=0)"); /* IE6-9 */
    

    【讨论】:

    • 这仍然是真的吗?我刚刚在我的 mixin 上测试了插值,它似乎并没有缩短我的十六进制颜色值。
    • Kyle,idk,你使用的是哪个版本的 SASS?
    • 我在 3.3.7(当前)
    【解决方案3】:

    更新您的语法以使用: 而不是= 进行属性定义:

    =mixin($variable) 
      property: value
      property: $variable
    

    查看SASS Reference,尽管示例是在 SCSS 而不是SASS indented style。完整的index of the SASS documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-27
      • 2020-09-10
      • 1970-01-01
      • 2016-04-27
      • 2018-04-06
      • 2021-09-27
      • 2012-09-11
      相关资源
      最近更新 更多