简体   繁体   中英

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

}

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM