LESS - Mix


Advertisements

Description

It is used to mix the two colors along with the opacity. It has the following parameters −

  • color1 − It represents a color object.

  • color2 − It represents a color object.

  • weight − It is an optional parameter that specifies weight of the element by providing percentage balance point between the two colors.

Example

The following example demonstrates the use of mix color operation in the LESS file −

<html>
   <head>
      <title>Mix</title>
      <link rel = "stylesheet" type = "text/css" href = "style.css"/>
   </head>

   <body>
      <h2>Example of Mix Color Operation</h2>
      <div class = "myclass">
         <p>Mixed color :<br>#b0897d</p>
      </div>
   </body>
</html>

Next, create the style.less file.

style.less

.myclass{
   height:100px;
   width:100px;
   padding: 30px 0px 0px 25px;
   background-color: mix(#b361b1, #acb148, 50%);
   color:white;
}

You can compile the style.less to style.css by using the following command −

lessc style.less style.css

Execute the above command; it will create the style.css file automatically with the following code −

style.css

.myclass {
   height: 100px;
   width: 100px;
   padding: 30px 0px 0px 25px;
   background-color: #b0897d;
   color: white;
}

Output

Follow these steps to see how the above code works −

  • Save the above html code in the mix.html file.

  • Open this HTML file in a browser, the following output will get displayed.

Less Mix
less_color_operation.htm
Advertisements