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
.container 1 { Â Â Â Â height : 200px ; Â Â Â Â width : 600px ; Â Â Â Â border : 1px solid black ; Â Â Â Â 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
.container 1 { Â Â Â Â height : 200px ; Â Â Â Â width : 600px ; Â Â Â Â border : 1px solid black ; Â Â Â Â 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 > Â Â Â Â < link rel = "stylesheet" href = "Style.css" > </ head > Â Â < body > Â Â Â Â < h2 style = "color: green;" >neveropen</ h2 > Â Â Â Â < div class = "container1" > Â Â Â Â Â Â Â Â < div class = "function" > Â Â Â Â Â Â Â Â Â Â Â Â < h3 >Screen</ 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 green as the first color and black as a second color and we can see the output color is also green.
Style.less
.container 1 { Â Â Â Â height : 200px ; Â Â Â Â width : 600px ; Â Â Â Â border : 1px solid black ; Â Â Â Â 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
.container 1 { Â Â Â Â height : 200px ; Â Â Â Â width : 600px ; Â Â Â Â border : 1px solid black ; Â Â Â Â 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 > Â Â Â Â < link rel = "stylesheet" href = "Style.css" > </ head > Â Â < body > Â Â Â Â < h2 style = "color: green;" >neveropen</ h2 > Â Â Â Â < div class = "container1" > Â Â Â Â Â Â Â Â < div class = "function" > Â Â Â Â Â Â Â Â Â Â Â Â < h3 >Screen</ 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-screen