.project{
$self=&;
.card{
#{$self}__name{
font-weight:bold;
}
.card__body{
display:flex
}
}}
I want to add classname "card__body" with variable some开发者_如何学Cthing like $self but here $self denotes "project" instead of hardcoding "card__body". Thanks in advance.
we need to use interpolation in sass using &
and #{&}
we are using second &
inside #{}
because we cannot use &&
.project{
$self=&;
.card{
#{$self}__name{
font-weight:bold;
}
& #{&}_body{ //this will result in '.card .card_body{ }'
display:flex;
}
&_body{ //this will result in '.card_body{ }' without parent nesting
display:flex;
}
}
}
get more details on sass interpolation here on official docs
精彩评论