目录

导入语句(Import Statements)

描述 (Description)

import语句可以包含一个保存路径的变量。 当您引用公共父目录时,这非常有用。

例子 (Example)

以下示例演示了在import statement使用variables -

<html>
   <head>
      <link rel = "stylesheet" href = "style.css" type = "text/css" />
      <title>LESS Variables in Import Statements</title>
   </head>
   <body>
      <div class = "myclass">
         <h2>Welcome to IoWiki</h2>
         <p>LESS is a CSS pre-processor that enables customizable, 
         manageable and reusable style sheet for web site.</p>
      </div>
   </body>
</html>

接下来创建style.less文件。

style.less

@path : "http://www.iowiki.com/less";
@import "@{path}/external1.less";
.myclass {
   color : #A52A2A;
}

以下代码将从https://www.iowiki.com/less/external1.less路径将external.less文件导入style.less -

external1.less

.myclass {
   background: #C0C0C0;
}

您可以使用以下命令将style.less编译为style.css -

lessc style.less style.css

执行上面的命令; 它将使用以下代码自动创建style.css文件 -

style.css

body {
   background: #C0C0C0;
}
p {
   color: #A52A2A;
}

输出 (Output)

请按照以下步骤查看上述代码的工作原理 -

  • 将上述html代码保存在less_variables_interpolation_import.html文件中。

  • 在浏览器中打开此HTML文件,将显示以下输出。

较少的进口报表
↑回到顶部↑
WIKI教程 @2018