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 color ranges, we get a variety of different output colors as a result which depends on which color blending method is being used. The screen() method generally gives a bright color as result.
Screen() Function: The working principle of screen() functions is quite similar to the mathematical multiplication operation. The white color works as 0 and the black color works as 1. When we put the second color with white, the result color is also white because as we know everything multiplies with 0 becomes 0, and when we put the first color with black color, then we get the same color in the resultant color because everything multiplied with 1 remains the same.Â
Â
Syntax:
<css property> : screen(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.
Return type: The return type for this function will be the color.
Example 1: In this example, we will use the green color as the first color and white as a 2nd color and we can see the white color in the output.
Style.less
| .container1{     height: 200px;     width: 600px;     border: 1pxsolidblack;     border-radius: 10px;     background-color: #313131;     color: white; }  Â.function {     text-align: center; }  Â.colors {     height: 150px;     width: 100%;     display: flex;     flex-direction: row;     justify-content: space-evenly;     align-items: center; }  Â.firstColor, .secondColor, .thirdColor {     height: 100px;     width: 100px; }  Â.firstColor {     background-color: #008000;     color: white; }  Â.secondColor {     background-color: #ffffff;     color: black; }  Â.thirdColor {     background-color: screen(#008000, #ffffff);     color: black; }  | 
To compile the Less.js code to CSS, use the following command:
lessc styles.less styles.css
Style.css
| .container1{     height: 200px;     width: 600px;     border: 1pxsolidblack;     border-radius: 10px;     background-color: #313131;     color: white; }  Â.function {     text-align: center; }  Â.colors {     height: 150px;     width: 100%;     display: flex;     flex-direction: row;     justify-content: space-evenly;     align-items: center; }  Â.firstColor, .secondColor, .thirdColor {     height: 100px;     width: 100px; }  Â.firstColor {     background-color: #008000;     color: white; }  Â.secondColor {     background-color: #ffffff;     color: black; }  Â.thirdColor {     background-color: #ffffff;     color: black; }  | 
HTML Code:
HTML
| <!DOCTYPE html> <html>  Â<head>     <title>LESS.js Color Blending Function</title>     <linkrel="stylesheet"href="Style.css"> </head>  Â<body>     <h2style="color: green;">neveropen</h2>     <divclass="container1">         <divclass="function">             <h3>Screen</h3>         </div>         <divclass="colors">             <divclass="firstColor">1st color</div>             <divclass="secondColor">2nd color</div>             <divclass="thirdColor">Result</div>         </div>     </div> </body>  Â</html> | 
Output:
 
Â
Example 2: In this example, we will use green as the first color and black as a second color and we can see the output color is also green.
Style.less
| .container1{     height: 200px;     width: 600px;     border: 1pxsolidblack;     border-radius: 10px;     background-color: #313131;     color: white; }  Â.firstColor, .secondColor, .thirdColor {     height: 100px;     width: 100px;     display: flex;     justify-content: center;     align-items: center; }  Â.function {     text-align: 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: #000000;     color: white; }  Â.thirdColor {     background-color: screen(#008000, #000000);     color: black; }  | 
To compile the Less.js code to CSS, use the following command:
lessc styles.less styles.css
Style.css
| .container1{     height: 200px;     width: 600px;     border: 1pxsolidblack;     border-radius: 10px;     background-color: #313131;     color: white; }  Â.firstColor, .secondColor, .thirdColor {     height: 100px;     width: 100px;     display: flex;     justify-content: center;     align-items: center; }  Â.function {     text-align: 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: #000000;     color: white; }  Â.thirdColor {     background-color: #008000;     color: black; }  | 
HTML Code:
HTML
| <!DOCTYPE html> <html>  Â<head>     <title>LESS.js Color Blending Function</title>     <linkrel="stylesheet"href="Style.css"> </head>  Â<body>     <h2style="color: green;">neveropen</h2>     <divclass="container1">         <divclass="function">             <h3>Screen</h3>         </div>         <divclass="colors">             <divclass="firstColor">1st color</div>             <divclass="secondColor">2nd color</div>             <divclass="thirdColor">Result</div>         </div>     </div> </body>  Â</html> | 
Output:
 
Â
Reference: https://lesscss.org/functions/#color-blending-screen

 
                                    







