Less教程
Less函数

Less image-width()

Less image-width()

Less image width函数用于检查文件中图像的宽度。
让我们举个例子演示在Less文件中使用图像宽度功能。
创建一个名为"simple.html"的HTML文件,其中包含以下数据。
HTML文件: 简单。 html
<!DOCTYPE html>
<head>
   <link rel="stylesheet" href="simple.css" type="text/css" />
</head>
<body>
    <h2>Welcome to lidihuo</h2>
    <h3>A solution of all technology.</h3>
</body>
</html>
现在创建一个名为"simple.less"的文件。它类似于CSS文件。唯一的区别是它以" .less"扩展名保存。
less 的文件: simple.less
body{
  background-image:url("image.jpg");
  width:image-width("image.jpg");
}
将文件"simple.html"和"simple.less"都放入Node.js的根文件夹中
现在,执行以下代码: lessc simple.less simple。 css
less 图像宽度function1
这将编译"simple.less "文件。将生成一个名为" simple.css"的CSS文件。
例如:
less 图像宽度function2
生成的CSS" simple.css"具有以下代码:
body {
  background-image: url("image.jpg");
  width: 700px;
}
在这里,您得到图像的宽度。
输出:
less 图像宽度function3
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4