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

Changing the selecting order with the & operator


The CSS selectors are pattern-matching rules that determine which style rules apply to the elements in the document tree. As can be read in the Referencing parent selectors with the & operator recipe, the & operator can be used inside nested rules in Less. Placing the & parent reference at the end of a selector inside a nested rule gives you the opportunity to change the selecting order.

Getting ready

For client-side compiling, you will have to create an index.html file that will load the example.less file and the less.js compiler with the following code in the head section:

<link rel="stylesheet/less" type="text/css" href="less/example.less">
<script src="js/less.js" type="text/javascript"></script>

How to do it…

  1. Create an example.less file and write the following Less code into it:

    p{ 
      font-size: 2em;
      color: darkgreen;
    
      footer & {
        font-size: 1em;
        color: darkred;
      }
    }
  2. Create an index.html file...