注释使代码清晰易懂,易于理解.您可以在代码中同时使用块样式和内联注释,但是当您编译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 文件.
/* 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 文件;
/* It displays the green color! */ .myclass { color: green; } .myclass1 { color: red; }
按照以下步骤查看上述代码的工作原理;
将上述html代码保存在 comments.html 文件中.
在浏览器中打开此HTML文件,将显示以下输出.