教程 > LESS 教程 > Less 特征 阅读:28

LESS 导入

LESS 导入用于导入 LESS 或 CSS 文件的内容。

示例

下面的例子演示了LESS文件中导入的使用

importing.html

<html>
   <head>
      <title>迹忆客(jiyik.com) - Less Importing</title>
      <link rel = "stylesheet" type = "text/css" href = "style.css" />
   </head>

   <body>
      <h1>Example using Importing</h1>
      <p class = "myclass">LESS enables customizable, 
      manageable and reusable style sheet for web site.</p>
      <p class = "myclass1">It allows reusing CSS code and 
      writing LESS code with same semantics.</p>
      <p class = "myclass2">LESS supports creating cleaner, 
      cross-browser friendly CSS faster and easier.</p>
   </body>
</html>

现在创建 myfile.less 文件。

myfile.less

.myclass {
   color: #FF8000;
}

.myclass1 {
   color: #5882FA;
}

接下来,创建文件 style.less。

style.less

@import "myfile.less";
.myclass2 {
   color: #FF0000;
}

myfile.less 文件将导入到 style.less

我们可以使用以下命令将 style.less 文件编译为 style.css

$ lessc style.less style.css

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

style.css

.myclass {
   color: #FF8000;
}

.myclass1 {
   color: #5882FA;
}

.myclass2 {
   color: #FF0000;
}

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

  • 将上述 html 代码保存在 importing.html 文件中。
  • 在浏览器中打开此 HTML 文件,将显示以下输出。

Less 导入

查看笔记

扫码一下
查看教程更方便