LESS - URLs



Description

The variables can be used to hold the URLs.

Example

The following example demonstrates the use of variables to hold URL in the LESS file −

<html>
   <head>
      <link rel = "stylesheet" href = "style.css" type = "text/css" />
      <title>LESS URLs</title>
   </head>

   <body>
      <div class = "myclass">
      </div>
   </body>
</html>

Now create the style.less file.

style.less

@images: "http://www.tutorialspoint.com";

.myclass {
   background : url("@{images}/less/images/less_variables/birds.jpg");
   width:800px;
   height:500px;
}

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 {
   background: url("http://www.tutorialspoint.com/less/images/less_variables/birds.jpg");
   width: 800px;
   height: 500px;
}

Output

Follow these steps to see how the above code works −

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

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

LESS URLs
less_variables.htm
Advertisements