目录

Namespaces

描述 (Description)

命名空间用于以通用名称对mixin进行分组。 使用名称空间,可以避免名称冲突,并从外部封装一组mixins。

例子 (Example)

以下示例演示了在LESS文件中使用mixin namespaces -

<html>
   <head>
      <link rel = "stylesheet" href = "style.css" type = "text/css" />
      <title>Mixin Namespaces</title>
   </head>
   <body>
      <h2>Welcome to IoWiki</h2>
      <p>LESS is a CSS pre-processor that enables customizable, 
      manageable and reusable style sheet for web site.</p>
   </body>
</html>

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

style.less

#outer() {
   background:yellow;
   .inner {
      color: red;
   }
}
p {
   #outer > .inner;
}

您可以使用以下命令将style.less编译为style.css -

lessc style.less style.css

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

style.css

p {
   color: red;
}

输出 (Output)

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

  • 将上述html代码保存在less_mixin_namespaces.html文件中。

  • 在浏览器中打开此HTML文件,将显示以下输出。

LESS Mixin命名空间
↑回到顶部↑
WIKI教程 @2018