Reputation: 2115
Is there a way to check what &
refers in mixin?
body {
@import x
}
button {
@import x
}
Inside @mixin x()
I want a special case when it's called with body
as &
.
Upvotes: 0
Views: 31
Reputation: 3456
You can check the value of &
in your mixin using @if {} @else {}
:
@mixin test {
$root: #{&};
$parentTagIsBody: $root == 'body';
@if $parentTagIsBody {
color: red;
} @else {
color: black;
}
}
button {
@include test;
}
body {
@include test;
}
will compile to:
button {
color: black;
}
body {
color: red;
}
Upvotes: 1