Less image width

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Less image width

The Less image width function is used to check the width of the image from the file.

Let's take an example to demonstrate the usage of image width function in Less file.

Create a HTML file named "simple.html", having the following data.

HTML file: simple.html

  1. >  
  2. <head>  
  3.    <link rel="stylesheet" href="simple.css" type="text/css" />  
  4. head>  
  5. <body>  
  6.     <h2>Welcome to JavaTpointh2>  
  7.     <h3>A solution of all technology.h3>  
  8. body>  
  9. html> 

Now create a file named "simple.less". It is similar to CSS file. The only one difference is that it is saved with ".less" extension.

Less file: simple.less

  1. body{  

  2.   background-image:url("image.jpg");  

  3.   width:image-width("image.jpg");  

  4. }  

Put the both file "simple.html" and "simple.less" inside the root folder of Node.js

Now, execute the following code: lessc simple.less simple.css

less image width function1

This will compile the "simple.less" file. A CSS file named "simple.css" will be generated.

For example:

less image width function2

The generated CSS "simple.css", has the following code:

  1. body {  

  2.   background-image: url("image.jpg");  

  3.   width: 700px;  

  4. }  

Here, you get the width of the image.

Output

less image width function3