我有这个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)}');
}
}
Run Code Online (Sandbox Code Playgroud)
$dir 是'方向'的缩写.
如果我需要制作$ie-filters'true'并且我不需要更改$dir/ $dir-webkit默认值,我仍然需要重新声明它们,这显然不是非常干燥和最佳,所以我必须这样做:
@include linear-gradient(#7a7a7a, #1a1a1a, bottom, top, true);
当我想要这样做时:
@include linear-gradient(#7a7a7a, #1a1a1a, true);
调用mixin时如何以这种方式跳过参数?
PS如果你想知道$dir-webkitWebkit 的论点,因为它仍然没有处理新的渐变语法(参见:http://generatedcontent.org/post/37949105556/updateyourcss3 - > 新的渐变语法),方向需要与标准语法相反.
mar*_*kus 55
从SASS 3.1开始,您可以传递命名参数来执行此操作:
@include linear-gradient($from: #7a7a7a, $to: #1a1a1a, $ie-filters: true);
Run Code Online (Sandbox Code Playgroud)
其余的将是默认的.
| 归档时间: |
|
| 查看次数: |
7320 次 |
| 最近记录: |