LESS - svg gradient Function


Advertisements

Description

The svg-gradient is a transition of one color to another. It can add many colors to the same element. It consists at least three parameters −

  • first parameter identifies the gradient type and direction.

  • other parameters list its position and color.

The colors specified at first and last position are optional. The direction can be set - to bottom, to right, to bottom right, to top right, ellipse or ellipse at center.

Parameters - colors stops in list −

  • list − lists all colors and their position.

  • escaped value or list of identifiers − sets the direction.

Parameters - color stops in arguments−

  • escaped value or list of identifiers − sets the direction.

  • color[percentage] pair − first color and its respective position.

  • color percent pair − second color and its respective position.

Example

The following example demonstrates the use of svg gradient in the LESS file −

misc_example.htm

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

   <body>
      <div class = "style">
         <h2>Welcome to TutorialsPoint</h2>
         <p>The largest Tutorials Library on the web.</p>
      </div>
   </body>
</html>

create the style.less file.

style.less

.style {
   @style: orange, green 30%, #LESS520;
   background-image: svg-gradient(ellipse, @style);
}

You can compile the style.less file 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

.style {
   background-image: url('data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20%3F
   %3E%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22
   %20version%3D%221.1%22%20width%3D%22100%25%22%20height%3D%22100
   %25%22%20viewBox%3D%220%200%201%201%22%20preserveAspectRatio%3D
   %22none%22%3E%3CradialGradient%20id%3D%22gradient%22%20gradientUnits
   %3D%22userSpaceOnUse%22%20cx%3D%2250%25%22%20cy%3D%2250%25%22%20r%3D%2275
   %25%22%3E%3Cstop%20offset%3D%220%25%22%20stop-color%3D%22%23ffa500%22%2F
   %3E%3Cstop%20offset%3D%2230%25%22%20stop-color%3D%22%23008000%22%2F
   %3E%3Cstop%20offset%3D%22100%25%22%20stop-color%3D%22%23LESS520%22%2F
   %3E%3C%2FradialGradient%3E%3Crect%20x%3D%22-50%22%20y%3D%22-50%22%20width%3D
   %22101%22%20height%3D%22101%22%20fill%3D%22url(%23gradient)%22%20%2F%3E%3C%2Fsvg%3E');
}

Output

Follow these steps to see how the above code works −

  • Save the above html code in the misc_example.htm file.

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

Less Misc Function
less_misc_functions.htm
Advertisements