0

In pure CSS if I want to declare the same property for 2 selectors, it's sufficient to separate these selectors with a comma such as:

#first_id,
.second_class
{
   color:red;
}

How can I make the same thing for 2 LESS Mixins declaration?

I would like to make something like this:

.generic_transition (@duration:1s),
.other_transition (@duration:1s)
{
  -webkit-transition:all @duration;
     -moz-transition:all @duration;
      -ms-transition:all @duration;
       -o-transition:all @duration;
          transition:all @duration;
}

But it does not run.... How to reach expected result? Thank you.

Luca Detomi
  • 5,564
  • 7
  • 52
  • 77

2 Answers2

0

You can add helper class for every mixin like this:

.other_transition (@duration:1s){
  .helper(@duration);
}

.generic_transition (@duration:1s){
  .helper(@duration); 
}

.helper(@duration){
  -webkit-transition:all @duration;
     -moz-transition:all @duration;
      -ms-transition:all @duration;
       -o-transition:all @duration;
          transition:all @duration;
}
Slawa Eremin
  • 5,264
  • 18
  • 28
0

Similar to Slawa's answer, but slightly less code. Since one of your names for mixins is already .generic_transition, then this works and is clear that .other_transition uses the generic transition's code:

.generic_transition (@duration:1s) {
  -webkit-transition:all @duration;
     -moz-transition:all @duration;
      -ms-transition:all @duration;
       -o-transition:all @duration;
          transition:all @duration;
}

.other_transition (@duration:1s) {
    .generic_transition (@duration);
}

It is unclear, however, why you would want two mixins defined exactly the same, as your original question has. That makes sense for selectors, but not as much for mixins. I'm assuming you want to set up some "generic" code for transitions, and then have that applied "generically" to any "other" transition.

Also, while your question does not necessarily deal with transitions, since that is what you used as an example, then this answer may prove useful to you.

Community
  • 1
  • 1
ScottS
  • 71,703
  • 13
  • 126
  • 146