LESS - List Length Function



Description

It will take a comma or space separated list of values as parameter and returns an integer representing the number of elements in a list.

Example

The following example demonstrates the use of length function in the LESS file −

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

   <body>
      <h2>Example using Length Function</h2>
      <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: "audi", "benz", "toyota","honda", "mahindra", "suzuki","volkswagen",
   "renault","bmw","tata","ford","skoda";
   @val: length(@list);
   font-size:@val;
}

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: 12;
}

Output

Follow these steps to see how the above code works −

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

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

less_list_functions.htm
Advertisements