LESS - Mixin Namespaces


Advertisements

Description

Namespaces are used to group the mixins under a common name. Using namespaces, you can avoid conflict in name and encapsulate a group of mixins from outside.

Example

The following example demonstrates the use of mixin namespaces in the LESS file −

<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>

Next, create the style.less file.

style.less

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

p {
   #outer > .inner;
}

You can compile the style.less to style.css by using the following command −

lessc style.less style.css

Execute the above command; it will create the style.css file automatically with the following code −

style.css

p {
   color: red;
}

Output

Follow these steps to see how the above code works −

  • Save the above html code in the less_mixin_namespaces.html file.

  • Open this HTML file in a browser, the following output will get displayed.

LESS Mixin Namespaces
less_mixins.htm
Advertisements