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 merge selectors


The :extend() pseudo class has been added to Less to merge selectors. In contrast to using a mixin to set the properties, the :extend() pseudo class can also be applied for composite selectors. Merging selectors with the :extend() pseudo class reduces the number of sectors that have the same properties in the compiled CSS code. Merged selectors reduce the size of your final CSS code.

Getting ready

In this recipe, you will compile two pieces of the Less code to see how the :extend() pseudo class works.

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. You can edit the code in this recipe with your favorite text editor.

How to do it…

  1. The :extend() pseudo class can be put directly on a selector, as shown in the following Less code:

    .class1{
      property: value;
    } 
    .class2:extend(.class1){};
  2. Write the preceding Less...