Nested Rules in LESS: LESS tutorial

In LESS, the nested rules is a group of CSS properties which enables using properties of one class into another class and includes class name as its properties.

Nested Rules in LESS

With LESS nesting you can simplify CSS selectors very easily. Just like HTML where first we write a parent tag then inside that tag we write its immediate children tags and inside those we write children tags of those immediate children.

Now have a look at the CSS code and see how we can simplify it with LESS. First look at the CSS code:

Using LESS we can write the above CSS code like this:


Here is an example of descendants. Using & sign we are actually referring the parent element itself.

The output:

This is very important to note because there will be times when you want the descendant operator, and times when you just want to target elements with specific classes.