LESS - List Extract Function
Description
It will return the value at a specified position in a list. It takes list (list of values separated by a comma or space) and index (integer specifying a position of an element to return) as parameters.
Example
The following example demonstrates the use of extract function in the LESS file −
<!doctype html>
<head>
<title>Extract Function</title>
<link rel = "stylesheet" href = "style.css" type = "text/css" />
</head>
<body>
<h1>Example of Extract Function</h1>
<p>LESS enables customizable, manageable and reusable style sheet for web site.</p>
</body>
</html>
Next, create the style.less file.
style.less
p {
@list: 10px, 20px, 30px, 40px;
@val: extract(@list, 2);
font-size:@val;
color:#F79F81;
}
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
p {
font-size: 20px;
color: #F79F81;
}
Output
Follow these steps to see how the above code works −
Save the above html code in the extract.html file.
Open this HTML file in a browser, the following output will get displayed.
less_list_functions.htm
Advertisements