我正在尝试在Sass中创建一个mixin,以生成多个背景,问题是背景的数量是未知的,可能是3、4甚至5。这是我尝试并失败的代码:
@mixin multiBg($page: index, $sec: sec01,$from: 1, $to: 3, $type: jpg){
$url: (); // i'm try to create a empty array first
$newUrl: null; // and an empty variable
@for $i from $from through $to {
$newUrl: append($url, url(../img/#{$page}/#{$sec}_bg0#{$i}.#{$type})); // then append value to variable;
}
background: $newUrl;
}
#sec05 {
@include multiBg(index,sec05);
}
当前输出:
background: url(../img/index/sec05_bg03.jpg);
预期输出:
background: url(../img/sec05_bg01.jpg),url(../img/sec05_bg02.jpg), url(../img/sec05_bg03.jpg);
由于我还在学习SASS,所以不知道该如何解决这个问题。请有经验的人指点一下。