LESS - 注释
说明
注释使代码对用户来说清晰易懂。您可以在代码中使用块样式和内联注释,但当您编译 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 文件,将显示以下输出。