Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing an empty LESS parameter to use default?

Tags:

css

less

If I have a LESS parametric mixin such as:

.trans (@what: all, @time: 0.2s, @type: ease-in-out) {
-webkit-transition: @arguments;
-moz-transition: @arguments;
-o-transition: @arguments;
-ms-transition: @arguments;
transition: @arguments; 
} 

It works as expected:

.myItem {
  .trans;
 }

But if I want to set the @time to 0.4s, I seem to have to pass an argument for the first item as well:

.trans(all, 0.4s);

Is there a syntax for just passing a null argument, so the default ("all") is simply used? This does not work, throws an error on compile:

.trans(,0.4s);

Thanks.

like image 454
Steve Avatar asked May 31 '26 11:05

Steve


1 Answers

Probably too late, but the response could be useful to others.

You can also name the variables when you're calling the mixin, without having to follow the order.

Considering your case:

 .trans (@what: all, @time: 0.2s, @type: ease-in-out) {  
   -webkit-transition: @arguments;  
   -moz-transition: @arguments;  
   -o-transition: @arguments;  
   -ms-transition: @arguments;  
   transition: @arguments; 
}

You could do something like .trans(@time:1s); or .trans(@type:linear, @what: opacity);

hope it helps.

like image 54
bravomartin Avatar answered Jun 02 '26 01:06

bravomartin