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 selectors inside mixins


Mixins in Less can not only contain properties, but also selectors. This recipe will show you how to leverage selectors inside mixins.

Getting ready

For this recipe, you will have to create a coloredlinks.less file and an index.html file, which load the Less file and less.js compiler with the following code in the head section:

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

How to do it…

In this recipe, you will create a mixin that gives a color and appends an icon or symbol to your hyperlinks by performing the following steps:

  1. Start this recipe by adding the .colored-links mixin to the coloredlinks.less file, as follows:

    .colored-links() {
      a {
        color:green;
        &::after {
          content: "\2764";
        }
      }
    }
  2. Now, add the following HTML code to the index.html file:

    <header>the header</header>
    <section>
    <p>this is a paragraph<br><a href...