The built-in default()
function plays a special role when leveraging mixins, especially mixin guards.
For this recipe, you will have to know something about parameterized mixins. You also need to be aware of what guards are and how to use them. You can find both in the Using mixin guards recipe in Chapter 6, Advanced Less Coding. You will also need a Less compiler, as discussed in Chapter 1, Getting to Grips with the Basics of Less.
Use the command-line
lessc
compiler to compile the following Less code:.mixin(1) { property: 1 * 2; } .mixin(2) { property: 2 * 3; } .mixin(@a) when (default()) { property: @a; } one { .mixin(1); } five { .mixin(5); }
The preceding Less code compiles into CSS, which looks like the following code:
one { property: 2; } five { property: 5; }