我有这个 mixin 来处理简单的 CSS3 线性渐变:
@mixin linear-gradient($from, $to, $dir: bottom, $dir-webkit: top, $ie-filters: false) {
background-color: $to;
background-image: -webkit-linear-gradient($dir-webkit, $from, $to);
background-image: linear-gradient(to $dir, $from, $to);
@if $ie-filters == true and $old-ie {
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{ie-hex-str($from)}', endColorstr='#{ie-hex-str($to)}');
}
}
$dir
是“方向”的缩写。
如果我需要做$ie-filters
“true”,我不需要改变$dir
/ $dir-webkit
默认值我仍然需要重新声明它们,这显然不是很干燥和最佳,所以我必须这样做:
@include linear-gradient(#7a7a7a, #1a1a1a, bottom, top, true);
当我只想这样做时:
@include linear-gradient(#7a7a7a, #1a1a1a, true);
调用 mixin 时如何以这种方式跳过参数?
PS如果你想知道$dir-webkit
参数它适用于 Webkit,因为它仍然无法处理新的渐变语法(请参阅:http:// generatedcontent.org/post/37949105556/updateyourcss3 http://generatedcontent.org/post/37949105556/updateyourcss3 -> 新的渐变语法),方向需要与标准语法相反。