Less.js Variables Combinatorial Explosion
Last Updated :
28 Apr, 2025
LESS works as an extension to the regular CSS and gives it some additional features to work with. , which is used to generate all possible combinations of the selector's list which are separated by a comma.
In this article, we are going to learn about the combinatorial explosion which is available in Less.js.
Syntax:
& + & {
<css-property> : value;
}
Parameter:
- It does not accept any parameters.
Example 1: In this example, we will generate all possible selector combinations of p and h2 elements and apply the text color to the contents of the respective elements, using the combinatorial explosion.
index.html:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Variable Combinatorial explosion</title>
<style>
p, h2 {
font-style: italic;
}
p + p,
p + h2,
h2 + p,
h2 + h2 {
color: green;
}
</style>
</head>
<body>
<h1 style="color:green">GeeksforGeeks</h1>
<h2>Variable Combinatorial explosion</h2>
<p>GeeksforGeeks</p>
</body>
</html>
style.less:
CSS
p, h2 {
font - style: italic;
& + & {
color: green;
}
}
Now, to compile the above LESS code to CSS code, run the following command:
lessc style.less style.css
The compiled CSS file comes to be:
style.css:
CSS
p,
h2 {
font - style: italic;
}
p + p,
p + h2,
h2 + p,
h2 + h2 {
color: green;
}
Output:
Example 2: In this example, we will use more than two selectors to generate all possible combinations of p, h2, li elements and apply the green color to them by using combinatorial explosion.
index.html:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Variable Combinatorial explosion</title>
<style>
p,
h2,
li,
a {
font-style: italic;
}
p + p,
p + h2,
p + li,
p + a,
h2 + p,
h2 + h2,
h2 + li,
h2 + a,
li + p,
li + h2,
li + li,
li + a,
a + p,
a + h2,
a + li,
a + a {
color: green;
}
</style>
</head>
<body>
<h1 style="color:green">GeeksforGeeks</h1>
<h2> This is heading 2 </h2>
<p>This is paragraph</p>
<li>list item 1</li>
<li>list item 2</li><br/>
<a href="www.geeksforgeeks.com">GeeksforGeeks</a>
</body>
</html>
style.less:
CSS
p, h2, li, a {
font-style: italic;
& + & {
color: green;
}
}
Now, to compile the above LESS code to CSS code, run the following command:
lessc style.less style.css
The compiled CSS file comes to be:
style.css:
CSS
p,
h2,
li,
a {
font-style: italic;
}
p + p,
p + h2,
p + li,
p + a,
h2 + p,
h2 + h2,
h2 + li,
h2 + a,
li + p,
li + h2,
li + li,
li + a,
a + p,
a + h2,
a + li,
a + a {
color: green;
}
Output:
Reference: https://lesscss.org/features/#parent-selectors-feature-combinatorial-explosion
Similar Reads
Less.js Variable Interpolation Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. This dynamic style sheet language gives CSS more functionality. LESS provides interoperability across browsers. A programming language called CSS pre-processor is
3 min read
Less.js Lazy Variables Evaluation Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. It is a dynamic style sheet language that boosts the functionality of CSS. Cross-browser interoperability is offered via LESS. CSS is improved and compiled for usa
3 min read
Less.js Browser Modify Variables LESS (Leaner Style Sheets) Â is an extension or superset to the CSS, which basically enhances the abilities of normal CSS and provides it with programmable superpowers like variables, functions, loops, various methods to do certain tasks, etc. In this article, we are going to take a look at updating
3 min read
Less.js Variables LESS (Leaner Style Sheets) is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. It is a dynamic style sheet language that enhances the working power of CSS. LESS supports cross-browser compatibility. CSS pre-processor is a s
4 min read
Less.js calc() Exception Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. Since CSS is a dynamic style sheet language, it is preferred. Because LESS is adaptable, it can be used by a variety of browsers. Only CSS that has been created an
3 min read
Less.js Installation LESS (Leaner Style Sheets) is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. It is a dynamic style sheet language that enhances the working power of CSS. LESS supports cross-browser compatibility. CSS pre-processor is a s
4 min read