Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate multiple selectors in less

I'm trying to do this:

.a:concat(.b, .c, .d)

Expecting this result:

.a.b, .a.c, .a.d {}

Obviously this won't work since there isn't a function called concat in LESS. Can we achieve this with something else?

Thanks

like image 955
srcrustaceo Avatar asked Feb 27 '26 10:02

srcrustaceo


1 Answers

That is not achieved with a pseudo-class, but with the & character in a nested rule:

.a {
  &.b, &.c, &.d {}
}

On an interesting note, there is in fact a pseudo-class being proposed for the upcoming Selectors standard, not as :concat() but as :matches(), with similar syntax. It's unimplemented outside of prefixes at the moment, but in the meantime, this is done a little differently with LESS.

like image 97
BoltClock Avatar answered Mar 01 '26 11:03

BoltClock



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!