Book Image

Less Web Development Cookbook

Book Image

Less Web Development Cookbook

Overview of this book

Table of Contents (19 chapters)
Less Web Development Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using the default() function


The built-in default() function plays a special role when leveraging mixins, especially mixin guards.

Getting ready

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.

How to do it…

  1. 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);
    }
  2. The preceding Less code compiles into CSS, which looks like the following code:

    one {
      property: 2;
    }
    five {
      property: 5;
    }

How it works…

The default() function returns true for the situation if no other mixin matches. Note that the default() function can only be used in the parametric...