命名空間用于在通用名稱下對mixin進行分組。 使用命名空間可以避免名稱沖突,并從外部封裝mixin組。
以下示例演示如何在LESS文件中使用 mixin命名空間:
<html> <head> <link rel="stylesheet" href="style.css" type="text/css" /> <title>Mixin Namespaces</title> </head> <body> <h2>Welcome to Tutorialspoint</h2> <p>LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.</p> </body> </html>
接下來,創(chuàng)建文件 style.less 。
#outer() { background:yellow; .inner { color: red; } } p { #outer > .inner; }
您可以使用以下命令將 style.less 編譯為 style.css :
lessc style.less style.css
接下來執(zhí)行上面的命令,它將用下面的代碼自動創(chuàng)建 style.css 文件:
p { color: red; }
讓我們執(zhí)行以下步驟,看看上面的代碼如何工作:
將以上html代碼保存在 less_mixin_namespaces.html 文件中。
在瀏覽器中打開此HTML文件,將顯示如下輸出。
更多建議: