Reputation: 1858
I'm trying to use the ampersand to bring parent selectors into a variable containing pseudo-class selectors:
.my-selector,
.my-other-selector {
@{pseudo-states} {
// rules
}
}
The following attempts all produced the literal variable content in the generated css:
@pseudo-states: &:hover, &:focus, &:active, &.active;
@pseudo-states: ~"&:hover, &:focus, &:active, &.active";
@pseudo-states: ~"\&:hover, \&:focus, \&:active, \&.active;
Any way to achieve this?
It seems that LESS simply doesn't process the contents of variables, so this question may come down to whether or not there's a way to change that.
Upvotes: 2
Views: 537
Reputation: 11820
Adopting one of examples linked in comments above, here's the most (so far) clean solution:
// usage:
.my-selector,
.my-other-selector {
.pseudo-states({
/* rules */
});
}
// impl.:
.pseudo-states(@-) {
&:hover, &:focus, &:active, &.active {@-();}
}
Upvotes: 4