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

Referencing to the parent selector more than once


The & parent referencing sign can be used multiple times in the same selector to reference the same parent. For instance, multiple parent references can be used to construct child and sibling combinatory selectors.

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.

How to do it…

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

    p { 
      color: green; 
      & + & { 
        color: red; 
      } 
    } 
  2. You will find that the preceding Less code will be compiled into the CSS code, as shown in the following code:

    p { 
      color: green; 
    } 
    p + p { 
      color: red; 
    }

How it works…

The compiler replaces the & + & code with p + p. The + sign creates an adjacent sibling combinatory selector in CSS. The selector selects a p HTML element directly...