IE特定过滤器(如-ms-filter)的Sass Mixin错误

时间:2010-07-29 22:44:03

标签: css css3 sass compass-sass blueprint-css

我正在尝试按下这样的按钮:

=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:预期的rparen令牌,是single_eq令牌

我很确定这是我对's的放置,但我不确定如何正确地写它。它可以工作,如果我传递十六进制值而不是!更轻,更暗,因为那样我可以像这样删除=符号:

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

3 个答案:

答案 0 :(得分:36)

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

=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

答案 1 :(得分:11)

插值#{}有时不起作用,因为它会缩短十六进制颜色值。例如,它会将#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 */

答案 2 :(得分:1)

更新语法,使用:代替=作为属性定义:

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

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