Is it possible to reuse classes inside of a Less function that is a variable?


@red: #F16251;

.smalltext { font-size: 10px }
.mediumtext { font-size: 12px }
.largetext { font-size: 14px }
.xtralargetext { font-size: 20px }

.myfunction(@size: smalltext, @color: @red) {
    @.{size}; /*  This will need to call the class defined above */
    color: @color;

How can this be done, if possible? The @.{size} throws an error. I would just like to call the function like so:

.myfunction(mediumtext, #000000);

and would like it to use the .mediumtext class rule. Possible? I am getting a compilation error on above code btw.

Question author Solomon-closson | Source



In short, no, currently we can't assign a mixin to a variable nor call a mixin by its name. For your example however there's "DR-based" (see Passing Rulesets to Mixins) way:

.medium-text {font-size: 12px}

.my-mixin(@size, @color) {
    color: @color;

.foo {
    .my-mixin({.medium-text}, red);
Answer author Seven-phases-max

Ask about this question here!