想,如果有可能,因为我觉得我的自我重复以下之类的事情使用与萨斯数组:可以在Sass中定义一个数组吗?
.donkey
h2
background-color= !donkey
.giraffe
h2
background-color= !giraffe
.iguana
h2
background-color= !iguana
想,如果有可能,因为我觉得我的自我重复以下之类的事情使用与萨斯数组:可以在Sass中定义一个数组吗?
.donkey
h2
background-color= !donkey
.giraffe
h2
background-color= !giraffe
.iguana
h2
background-color= !iguana
不,这是不可能的。要做到这一点,最好的方法是定义一个mixin:
+animal-h2(!name, !color)
.#{name} h2
background-color= !color
然后你就可以有每款一条线,而不是三个:
+animal-h2("donkey", !donkey)
+animal-h2("giraffe", !giraffe)
+animal-h2("iguana", !iguana)
NEX3的答案是正确的。为了得到这个工作与上海社会科学院on Rails的3.1,我需要有一个css.scss文件中的以下内容:
$donkey: #CC4499;
@mixin animal-h2($name, $color) {
.#{$name} h2 {
background-color: $color;
}
}
@include animal-h2("donkey", $donkey);
@include animal-h2("horse", #000);
哪个输出:
.donkey h2 {
background-color: #CC4499;
}
.horse h2 {
background-color: black;
}
绝对。
$animals: "donkey", "giraffe", "iguana"
@foreach $animal in $animals
.#{$animal}
h2
background-color: !#{$animal}
贾斯汀是对的。我已经使用了[Sass lists](http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#lists)来获得乐趣和利润,并且可以证明它们的实用性。在阅读了Sass列表之后,您还应该查看Sass的列表函数,该函数在[here](http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#list-functions)中找到。他们几乎从来没有帮助,但他们可以真正让你的生活在某些情况下更容易! – Bitmanic 2012-05-02 03:42:49
这就是我正在寻找的东西,谢谢 – 2009-12-15 09:48:07