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 @rest... variable to use mixins with a variable number of arguments


As you can also see in the Using mixins with multiple parameters and Using duplicate mixin names recipes, only matching mixins are compiled into the final CSS code. In some situations, you don't know the number of parameters or want to use mixins for some style rules no matter the number of parameters. In these situations, you can use the special ... syntax or the @rest... variable to create mixins that match independent of the number of parameters.

Getting ready

You will have to create a file called rest.less, and this file can be compiled with the command-line lessc compiler, as described in the Installing the lessc compiler with npm in Chapter 1, Getting to Grips with the Basics of Less. You can edit the Less code with your favorite editor.

How to do it…

  1. Create a file called rest.less that contains the following Less code:

    .mixin(@a...) 
    { 
      .set(@a) when (iscolor(@a)) { 
        color: @a; 
      } 
      .set(@a) when (length...