Less.js Color Blending multiply() Function
Last Updated :
27 Sep, 2022
In this article, we will see the Color Blending multiply() Function in LESS.js. Less.js is an extension to the traditional CSS, it comes with additional features that will help us to write CSS code more conveniently. Color blending is a method that takes the intersection of two colors, or generally, we can say that when we mix two colors to obtain a different color value it is referred to as color blending. In Less, we use different methods to blend the color, one of them we are covering in this article is the multiply() Function. When we use this method, as a result, we get a slightly darker range of colors, this function is explained below.
The multiply() function work as a simple mathematics multiply operation. This function is used to multiply the 2 colors & then corresponding RGB channels for both the colors will be multiplied & will be divided by 255. The resultant color will be a darker color.
The black color works as 0 and the white color work as 1. So any color multiplied by black or 0, it will be black, for example, multiply(red, black) the result will be black, on the other hand when any color or its value is multiplied by white or 1 it will be the same color, so any color multiplies with white it will the same color, and if any color between white and black is multiplied with some color then we will get a different shade of color.
Syntax:
multiply(<first color>, <second color>);
Parameter values:
- first color: it accepts a color value, that could be HEX value, RGB value, or absolute color name.
- Second color: it also accepts a color value, which could be a HEX value, RGB value, or absolute color name.
Example 1: In this example, we will see the working of the multiply function, we will use completely black to multiply with green color, and we can see that the output is also black color.
Style.less:
.container1 {
height: 200px;
width: 600px;
border: 1px solid black;
border-radius: 10px;
}
.function {
text-align: center;
}
.firstColor,
.secondColor,
.thirdColor {
height: 100px;
width: 100px;
display: flex;
justify-content: center;
align-items: center;
}
.colors {
height: 150px;
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-evenly;
align-items: center;
}
.firstColor {
background-color: green;
color: white;
}
.secondColor {
background-color: black;
color: white;
}
.thirdColor {
background-color: multiply(green,black);
color: white;
}
To compile the Style.less code into style.css, use the following command:
lessc stye.less style.css
Style.css:
.container1 {
height: 200px;
width: 600px;
border: 1px solid black;
border-radius: 10px;
}
.function {
text-align: center;
}
.firstColor,
.secondColor,
.thirdColor {
height: 100px;
width: 100px;
display: flex;
justify-content: center;
align-items: center;
}
.colors {
height: 150px;
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-evenly;
align-items: center;
}
.firstColor {
background-color: green;
color: white;
}
.secondColor {
background-color: black;
color: white;
}
.thirdColor {
background-color: #000000;
color: white;
}
HTML
<!DOCTYPE html>
<html>
<head>
<title>Less.js Color Blending Function</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2 style="color: green;">GeeksforGeeks</h2>
<div class="container1">
<div class="function">
<h3>Multiply</h3>
</div>
<div class="colors">
<div class="firstColor">1st color</div>
<div class="secondColor">2nd color</div>
<div class="thirdColor">Result</div>
</div>
</div>
</body>
</html>
Output:
Example 2: In this example, we will use the 2nd color as white in the multiply function and we can see there is no change in the output color.
Style.less:
.container1 {
height: 200px;
width: 600px;
border: 1px solid black;
border-radius: 10px;
}
.function {
text-align: center;
}
.firstColor,
.secondColor,
.thirdColor {
height: 100px;
width: 100px;
display: flex;
justify-content: center;
align-items: center;
}
.colors {
height: 150px;
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-evenly;
align-items: center;
}
.firstColor {
background-color: green;
color: white;
}
.secondColor {
background-color: white;
color: white;
}
.thirdColor {
background-color: multiply(green,white);
color: white;
}
To compile the Style.less code into style.css, use the following command:
lessc stye.less style.css
Style.css:
.container1 {
height: 200px;
width: 600px;
border: 1px solid black;
border-radius: 10px;
background-color: #313131;
color: white;
}
.function {
text-align: center;
}
.firstColor,
.secondColor,
.thirdColor {
height: 100px;
width: 100px;
display: flex;
justify-content: center;
align-items: center;
}
.colors {
height: 150px;
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-evenly;
align-items: center;
}
.firstColor {
background-color: #008000;
color: white;
}
.secondColor {
background-color: #ffffff;
color: black;
}
.thirdColor {
background-color: #008000;
color: white;
}
HTML
<!DOCTYPE html>
<html>
<head>
<title>Less.js Color Blending Function</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2 style="color: green;">GeeksforGeeks</h2>
<div class="container1">
<div class="function">
<h3>Multiply</h3>
</div>
<div class="colors">
<div class="firstColor">1st color</div>
<div class="secondColor">2nd color</div>
<div class="thirdColor">Result</div>
</div>
</div>
</body>
</html>
Output:
Reference: https://lesscss.org/functions/#color-blending-multiply
Similar Reads
Less.js Color Blending overlay() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. CSS is more functional because of this dynamic style sheet language. Cross-browser interoperability is a feature of LESS. A computer language known as the CSS pre-
4 min read
Less.js Color Blending Functions
In this article, we are going to see Color Blending Functions in Less.js. Less (Leaner Style Sheets) is an extension to normal CSS code which basically enhances the abilities of normal CSS and provides it superpowers. Color blending functions are provided by Less.js to basically perform blending op
5 min read
Less.js Color Blending negation() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. Because it uses a dynamic style sheet language, CSS is more useful. LESS is adaptable enough to function in a variety of browsers. In order for web browsers to use
4 min read
Less.js Color Blending softlight() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. Because of this dynamic style sheet language, CSS is more useful. Interoperability between browsers is a characteristic of LESS. The CSS pre-processor is a compute
4 min read
Less.js Color Blending screen() Function
In this article, we will see the Color Blending screen() Function in LESS.js, along with understanding its basic implementation through the illustrations. Less.js is basically a CSS tool that provides additional features to traditional CSS. Color blending means when we blend or mix two separate colo
4 min read
Less.js Color Blending average() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. CSS is more beneficial because it makes use of a dynamic style sheet language. LESS is flexible enough to work in a wide range of browsers. The CSS pre-processor i
4 min read
Less.js Color Blending hardlight() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. CSS is more practical as a result of its dynamic style sheet language. LESS has the flexibility to work with different browsers. A computer language called the CSS
4 min read
Less.js Color Blending exclusion() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. Because it uses a dynamic style sheet language, CSS is more useful. LESS is adaptable enough to function in a variety of browsers. In order for web browsers to use
4 min read
Less.js Color Blending difference() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. Because it uses a dynamic style sheet language, CSS is more useful. LESS is adaptable enough to function in a variety of browsers. In order for web browsers to use
4 min read
Less.js Color Channel blue() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. Because of this dynamic style sheet language, CSS is more useful. Interoperability between browsers is a characteristic of LESS. The CSS pre-processor is a compute
3 min read