Tuesday, November 19, 2024
Google search engine
HomeLanguagesJavascriptLess.js Color Definition rgba() Function

Less.js Color Definition rgba() Function

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

In this article, we will see the Color Definition rgba() function in Less.js, along with understanding the basic implementation through the illustration. The rgba() function is utilized to generate a transparent color object of rgba types from hex value, RGB value, HSL or HSV value, and decimal values of red, green, blue, and alpha values.  So this function takes the hex value, RGB value, HSL or HSV value and it returns a string which is the rgba value. This color format is generally utilized in android development, Internet Explorer and .NET.

Syntax:

rgba(color);

Parameter value:

  • color: This is the compulsory parameter which is a color object, it can be a hex value, RGB value, HSL, or HSV value.

Return type: It returns the string as a final value.

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 definition rgba() function.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <link rel="stylesheet" 
          type="text/css" 
          href="style.css"/>
</head>
  
<body>
    <h1 style="color:green">neveropen</h1>  
    <h3>Less.js Color Blending rgba() Function</h3>
    <div class="c1">  
        <p>
            rgba(hsla(27, 55%, 40%, 0.6))<br>
           (Color Object)<br>rgba(158, 96, 46, 0.6)
          </p>  
    </div>
</body>
  
</html>


styles.less:

CSS




@body-bg-color: #eeeeee;
@color: rgba(hsla(27, 55%, 40%, 0.6));
  
.c1 
{  
    width: 250px;  
    height: 150px;  
    margin: 1rem;
    background-color: @color;  
}  
p{  
    padding: 40px 0px 0px 20px;  
}


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

lessc style.less style.css

The compiled CSS file comes to be: 

style.css:

CSS




.c1 
{
    width: 250px;
    height: 150px;
      margin: 1rem;
      background-color: rgba(158, 96, 46, 0.6);
}
{
      padding: 40px 0px 0px 20px;
}


Output:

 

Example 2: The below code example demonstrates the usage and implementation of the Color Definition rgb() 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="style.css"/>
</head>
  
<body>
    <h1 style="color:green">neveropen</h1>  
    <h3>Less.js Color Blending rgba() Function</h3>
    <div class="c1">  
        <p>
            rgba(#3c0606b3)<br>
           (Color Object)<br>rgba(60, 6, 6, 0.70196078)
          </p>  
    </div>
</body>
  
</html>


styles.less:

CSS




@body-bg-color: #eeeeee;
@color: hsl(150, 100%, 39%);
@second: rgba(#3c0606b3);
@cond: boolean(iscolor(@second));
  
.c1 
{  
    width: 250px;  
    height: 150px;  
    margin: 1rem;
    background-color: if(@cond, @color, @second);  
}  
p
{  
    padding: 50px 0px 0px 60px;  
    color: if(@cond, @second, @color);
}


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

lessc style.less style.css

The compiled CSS file comes to be: 

style.css:

CSS




.c1 
{
    width: 250px;
      height: 150px;
      margin: 1rem;
      background-color: hsl(150, 100%, 39%);
}
{
      padding: 50px 0px 0px 60px;
      color: rgba(60, 6, 6, 0.70196078);
}


Output:

 

Reference: https://lesscss.org/functions/#color-definition-rgba 

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments