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 extend to reduce the compiled CSS size


In this recipe, you will see how to use Less's :extend() pseudo class to reduce the size of the compiled CSS code.

Getting ready

You can compile the Less code in this recipe with the command-line lessc compiler, as described in the Installing the lessc compiler with npm recipe in Chapter 1, Getting to Grips with the Basics of Less. Use your favorite text editor to create and edit the Less files used in this recipe.

How to do it…

  1. Write the following Less code into a Less file and compile this file with the command-line lessc compiler:

    .mixin() {
      property1: value;
      property2: value;
    }
    .class1 {
      .mixin;
    }
    .class2 {
      .mixin;
    }
  2. You will find that the preceding Less code will compile into the following CSS code:

    .class1 { 
      property1: value; 
      property2: value; 
    } 
    .class2 { 
      property1: value; 
      property2: value; 
    }
  3. Now rewrite your Less code, leveraging Less's :extend() pseudo class. Your Less code will now look as follows:

    .mixin {
      property1:...