LESS - 不輸出 Mixin



描述

可以建立一個 mixin,並且可以透過簡單地在它後面放置括號使其在輸出中消失。

示例

以下示例演示了在 LESS 檔案中使用mixin

<html>
   <head>
      <link rel = "stylesheet" href = "style.css" type = "text/css" />
      <title>LESS Mixins</title>
   </head>

   <body>
      <div class = "myclass">
         <h1>Welcome to Tutorialspoint</h1>
         <p>LESS is a CSS pre-processor that enables customizable, 
         manageable and reusable style sheet for web site.</p>
      </div>
   </body>
</html>

接下來,建立style.less檔案。

style.less

.a() {
   padding-left: 100px;
}

.myclass {
   background : #64d9c0;
   .a;
}

您可以使用以下命令將style.less編譯為style.css

lessc style.less style.css

執行上述命令;它將自動建立style.css檔案,其中包含以下程式碼:

style.css

.myclass {
   background: #64d9c0;
   padding-left: 100px;
}

輸出

按照以下步驟檢視上述程式碼的工作原理:

  • 將上述 html 程式碼儲存在less_mixin_not_outputting.html檔案中。

  • 在瀏覽器中開啟此 HTML 檔案,將顯示以下輸出。

LESS Mixins
less_mixins.htm
廣告

© . All rights reserved.