Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
LESS WEB DEVELOPMENT ESSENTIALS

You're reading from   LESS WEB DEVELOPMENT ESSENTIALS Use CSS preprocessing to streamline the development and maintenance of your web applications

Arrow left icon
Product type Paperback
Published in Apr 2014
Publisher
ISBN-13 9781783981465
Length 202 pages
Edition Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Bass Jobsen Bass Jobsen
Author Profile Icon Bass Jobsen
Bass Jobsen
Arrow right icon
View More author details
Toc

The & symbol


The & symbol plays a special and important role in Less. It refers to the parent of the current selector and you can use it to reverse the order of nesting and to extend or merge classes. You will see that the following example will tell you more than what can be expressed in a thousand words:

.class1
{
  .class2{
    property: 5;
  }
}
 
.class1
{
  .class2 & {
    property: 5;
  }
}

This code will compile into the following code:

.class1 .class2 {
  property: 5;
}
.class2 .class1 {
  property: 5;
}

You can see that .class2 becomes the parent of .class1 when you use the & symbol after it. The & symbol can also be used in order to reference nesting that is outside the mixin.

The & symbol can also be used to nest and append pseudo classes to a class. Later on, you will see that you can use it to append classes too. A simple example of this will be adding a :hover pseudo class triggered by a mouse hover to a link, as shown in the following code:

.hyperlink{
...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image