- 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 - Mixins with Multiple Parameters
Description
Parameters can be separated using commas or semicolon. Using the comma symbol, you can interpret it as mixin parameters separator or css list separator. If you use semicolon inside mixin, then it separates the arguments by semicolons and CSS lists will be having all the commas.
It includes some points on semicolons and commas as listed below −
If you have two arguments, then the arguments will contain commas separated list. For instance, .class1(1, 2, 3; sometext, other thing).
If there are three arguments, the arguments will include only numbers such as .class1(1, 2, 3).
You can use dummy semicolon with comma separated list like .class1(1, 2, 3;).
There is comma separated default value. For instance .class1(@color: gray, green;)
Syntax
.mixin_name(@var_name1; @var_name2:some) { //code here }
Example
The following example demonstrates the use of mixin multiple parameters in the LESS file −
<!doctype html> <head> <title>Mixin Multiple Parameters</title> <link rel = "stylesheet" href = "style.css" type = "text/css" /> </head> <body> <h2>Example of Mixin Multiple Parameters</h2> <p class = "myclass">LESS enables customizable, manageable and reusable style sheet for web site.</p> </body> </html>
Next, create the style.less file.
style.less
.mixin(@color) { color: @color; } .mixin(@color; @padding: 2) { color: @color; padding: @padding; } .myclass { .mixin(#FE9A2E); }
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 { color: #FE9A2E; padding: 2; }
Output
Follow these steps to see how the above code works −
Save the above html code in the mixin_multiple_param.html file.
Open this HTML file in a browser, the following output will get displayed.