Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

possible to define an array in Sass?

Tags:

sass

haml

wondering if it is possible to use an array with Sass as I find my self repeating the following sort of thing:

.donkey
  h2
    background-color= !donkey

.giraffe
  h2
    background-color= !giraffe

.iguana
  h2
    background-color= !iguana
like image 926
Dr. Frankenstein Avatar asked Dec 14 '09 21:12

Dr. Frankenstein


2 Answers

Absolutely.

$animals: "donkey", "giraffe", "iguana"
@foreach $animal in $animals
  .#{$animal}
    h2
      background-color: !#{$animal}
like image 51
Justin Maxwell Avatar answered Sep 26 '22 03:09

Justin Maxwell


No, this isn't possible. The best way to do it is to define a mixin:

+animal-h2(!name, !color)
  .#{name} h2
    background-color= !color

Then you can have one line per style, rather than three:

+animal-h2("donkey", !donkey)
+animal-h2("giraffe", !giraffe)
+animal-h2("iguana", !iguana)
like image 26
Natalie Weizenbaum Avatar answered Sep 26 '22 03:09

Natalie Weizenbaum