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

LESS 注释

Less 注释使代码对用户来说清晰易懂。 我们可以在代码中同时使用块样式和内联注释,但是当我们编译 LESS 代码时,CSS 文件中不会出现单行注释。

示例

下面的例子演示了LESS文件中注释的使用

comments.html

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

   <body>
      <h1>Example using Comments</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>
   </body>
</html>

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

style.less

/* It displays the
green color! */
.myclass {
   color: green;
}

// It displays the blue color
.myclass1 {
   color: red;
}

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

$ lessc style.less style.css

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

style.css

/* It displays the
green color! */
.myclass {
   color: green;
}

.myclass1 {
   color: red;
}

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

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

Less 注释

查看笔记

扫码一下
查看教程更方便