user3774858
user3774858

Reputation: 31

How can I create a Sass mixin with a class as a variable

I am trying to write something like this :

@mixin variableChild($child:".theChild") {
    //some css
    $child {
     //css specific to the child
    }

}

#parent { @include variableChild(".specificChild"); };

So it would generate this CSS :

#parent {//some css}
#parent .specificChild {
   //css specific to the child

}

Upvotes: 1

Views: 1964

Answers (1)

LeBen
LeBen

Reputation: 2049

You were almost right, you just missed the #{} around your child selector I think. There’s more information about it in the Sass documentation.

@mixin variableChild($child:".theChild") { 
    #{$child} {
        color: red;
    }
}

#parent {
    @include variableChild(".specificChild");
};

http://jsfiddle.net/UrLdB/

Upvotes: 7

Related Questions