Less.js Color Channel green() 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 computer language that is used to augment and compile CSS so that web browsers may use it. In addition, it is an extension to the CSS language that offers features like variables, functions, mixins, and operations that enable us to develop dynamic CSS while maintaining backward compatibility.

Less.js Color Channel green() Function is used to extract the green channel of the color object. It returns a positive decimal value.  It takes values in hex codes, RGB values, HSL values, and HSV values.

Syntax:

green(value);

 

Parameters:

  • value: This is the parameter that is compulsory for the green function. It takes values in hex codes, RGB values, HSL values, and HSV values.

Example 1: The code below demonstrates the usage and implementation of the Color Channel green() function.

index.html




<!DOCTYPE html>
<html>
  
<head>
    <link rel="stylesheet" type="text/css" 
          href="style.css"/>
</head>
  
<body>
    <h1 style="color:green">w3wiki</h1
    <h3><b>Less.js Color Channel 
      green() Function</b></h3>
    <div class="container">
        <p class="text">Box</p>
    </div>
</body>
  
</html>


styles.less




@body-bg-color: #eeeeee;
@text-color: rgb(0, 200, 100);
@container-bg: rgb(220, 43, 55);
  
body {
    background: @body-bg-color;
}
  
.container{
    height:100px;  
    width: 100px;  
    padding: 30px 0px 0px 25px;  
    background-color: (#cc3eff);  
    color:yellow;  
}
.text{
    font-weight: green(rgb(123, 200, 0));  
}


Now, to compile the above LESS code to CSS code, run the following command:

lessc styles.less styles.css

The compiled CSS file comes to be: 

styles.css




body {
    background: #eeeeee;
}
.container {
    height: 100px;
    width: 100px;
    padding: 30px 0px 0px 25px;
    background-color: #cc3eff;
    color: yellow;
}
.text {
    font-weight: 200;
}


Output:

 

Example 2: The code below demonstrates the usage and implementation of the Color Channel green() function with the if and boolean logical functions.

index.html




<!DOCTYPE html>
<html>
  
<head>
    <link rel="stylesheet" type="text/css" 
          href="style.css"/>
</head>
  
<body>
    <h1 style="color:green">w3wiki</h1
    <h3><b>Less.js Color Channel 
      green() Function</b></h3>
    <div class="container">
        <p class="text">Box</p>
    </div>
</body>
  
</html>


styles.less




@body-bg-color: #eeeeee;
@text-color: rgb(80, 188, 134);
@container-bg: rgb(255, 178, 24);
@cond1: boolean(green(@text-color) < 50%);
  
body {
   background: @body-bg-color;
}
  
.container{
   height:100px;    
   width: 150px;  
   padding: 30px 0px 0px 25px;  
   background-color: #6a001e;  
   color:yellow;  
}
.text{
   font-weight: if(@cond1, bold, bolder);  
}


Now, to compile the above LESS code to CSS code, run the following command:

lessc styles.less styles.css

The compiled CSS file comes to be: 

styles.css




body {
    background: #eeeeee;
}
.container {
    height: 100px;
    width: 150px;
    padding: 30px 0px 0px 25px;
    background-color: #6a001e;
    color: yellow;
}
.text {
    font-weight: bolder;
}


Output:

 

Reference: https://lesscss.org/functions/#color-channel-green