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

Creating a color variant with the darken() and lighten() functions


In this recipe, you will compile some shades of green into CSS with the Less color operation functions.

Getting ready

You will need a valid HTML5 document, which includes the less.js compiler and a Less file called project.less. Note that the Using the built-in functions of Less recipe in Chapter 1, Getting to Grips with the Basics of Less, will show you an example of how to darken colors with the darken() built-in function.

How to do it…

  1. Write the following HTML code into your HTML5 file:

    <div>
      <div class="green">Shades of green</div>
    </div>
  2. Open the project.less file with your text editor and write the following Less code into it:

    @start-color: green;
    div.green {
      background-color: @start-color;
      color: contrast(@start-color);
      border: e(%("5px solid %a",darken(@start-color,10%)));
      &:hover {
        background-color: fadeout( @start-color,50%);
      }
    }
  3. Don't forget to link the project.less file in the...