注释使得代码清晰,使用户能够方便理解。您可以在代码中使用这两种注释:区块样式和内联注释,但是当你编译 Less 代码,单行注释将不会出现在CSS文件。
示例
下面的例子演示了Less文件中使用的注释:
<html> <head> <title>Less Comments</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文件,得到如下输出显示。