- Less Basic Tutorial
- Less - Home
- Less - Overview
- Less - Installation
- Language Features
- Less - Nested Rules
- Less - Nested Directives and Bubbling
- Less - Operations
- Less - Escaping
- Less - Functions
- Less - Namespaces and Accessors
- Less - Scope
- Less - Comments
- Less - Importing
- Less - Variables
- Less - Extend
- Less - Mixins
- Less - Parametric Mixins
- Less - Mixins as Functions
- Less - Passing Rulesets to Mixins
- Less - Import Directives
- Less - Import Options
- Less - Mixin Guards
- Less - CSS Guards
- Less - Loops
- Less - Merge
- Less - Parent Selectors
- Functions
- Less - Misc Functions
- Less - String Functions
- Less - List Functions
- Less - Math Functions
- Less - Type Functions
- Less - Color Defination Functions
- Less - Color Channel Functions
- Less - Color Operation
- Less - Color Blending Functions
- Usage
- Less - Command Line Usage
- Using Less In The Browser
- Less - Browser support
- Less - Plugins
- Less - Programmatic Usage
- Less - Online Compilers
- Less - GUIs
- Less - Editors and Plugins
- Less - Third Party Compilers
- Less - Frameworks
- Less Useful Resources
- Less - Quick Guide
- Less - Useful Resources
- Less - Discussion
LESS - svg gradient Function
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.