Open In App

Less.js Color Operation fadeout() Function

Last Updated : 06 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. Since CSS uses a dynamic style sheet language, it is superior. LESS is adaptable enough to function in a variety of browsers. A computer language called the CSS pre-processor is used to develop and enhance CSS so that web browsers may use it. Additionally, it is an extension to the CSS language that offers tools like variables, functions, mixins, and operations to aid in the creation of dynamic CSS while maintaining backward compatibility.

In this article, we are going to discuss the Color Operation fadeout() function in Less.js, along with knowing their basic implementation through the illustration.

The fadeout() function is to regulate the exact opacity of a color object. Opacity can be set or reset. So this function takes hex value, RGB value, HSL or HSV value and it returns a value with that required opacity.

 

Syntax:

fadeout(color, amount)

Parameter values:

  • color: This is the first parameter and it is compulsory, it can be a hex value, RGB value, HSL, or HSV value.
  • amount: This parameter is also compulsory and it signifies the amount of opacity that is needed to be applied. This parameter takes a value from 0-100% range.

Please refer to the how to pre-compile LESS into CSS article for a detailed description.

Example 1: The below code example demonstrates the usage and implementation of the Color Operation fadeout() function in Less.js

HTML




<!DOCTYPE html>
<html>
  
<head>
    <link rel="stylesheet" 
        type="text/css" href="styles.css" />
</head>
  
<body>
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
      
    <h3>Less.js Color Operation fadeout() Function</h3>
      
    <div class="c1">
        <p>
            fadeout(hsl(90, 100%, 50%), 25%)<br>
            (HSLA Value)<br>hsla(90, 100%, 50%, 0.75)
        </p>
    </div>
</body>
  
</html>


styles.less




@body-bg-color: #eeeeee;
  
body{
    background-color: @body-bg-color;
}
.c1 {  
    width: 350px;  
    height: 150px;  
    margin: 1rem;
    background-color: fadeout(hsl(90, 100%, 50%), 25%);  
}  
p{  
    padding: 40px 0px 0px 20px;  
}


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

lessc styles.less styles.css

The CSS output of the above Less file was compiled

styles.css




body {
    background-color: #eeeeee;
}
  
.c1 {
    width: 350px;
    height: 150px;
    margin: 1rem;
    background-color: hsla(90, 100%, 50%, 0.75);
}
  
p {
    padding: 40px 0px 0px 20px;
}


Output:

 

Example 2: The below code example demonstrates the usage and implementation of the Color Operation fadeout() function with the if() and boolean logical functions and the color type function.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <link rel="stylesheet" 
        type="text/css" href="styles.css" />
</head>
  
<body>
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
      
    <h3>Less.js Color Operation fadeout() Function</h3>
      
    <div class="c1">
        <p>
            fadeout(hsla(90, 100%, 50%, 0.9), 15%)<br>
            (HSLA Value)<br>hsla(90, 100%, 50%, 0.75)
        </p>
    </div>
</body>
  
</html>


styles.less




/* styles.less */
@body-bg-color: #eeeeee;
@color: hsl(150, 100%, 39%);
@second: rgb(29, 0, 0);
@hex: fadeout(hsla(90, 100%, 50%, 0.9), 15%);
@cond1: boolean(iscolor(@hex));
  
body {
    background-color: @body-bg-color;
}
  
.c1 {
    width: 350px;
    height: 150px;
    margin: 1rem;
    background-color: if(@cond1, @second, @color);
}
  
p {
    padding: 30px 0px 0px 25px;
    color: @hex;
}


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

lessc styles.less styles.css

The CSS output of the above Less file was compiled.

styles.css




/* styles.less */
body {
    background-color: #eeeeee;
}
  
.c1 {
    width: 350px;
    height: 150px;
    margin: 1rem;
    background-color: #1d0000;
}
  
p {
    padding: 30px 0px 0px 25px;
    color: hsla(90, 100%, 50%, 0.75);
}


Output:

 

Reference: https://lesscss.org/functions/#color-operations-fadeout 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads