LESS - 變數插值屬性



描述

變數可以透過屬性引用。

示例

以下示例演示了在 LESS 檔案中使用變數透過屬性引用的方法:

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

   <body>
      <div class = "myclass">
         <h2>Welcome to Tutorialspoint</h2>
         <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

@my-property: color;
.myclass {
   background-@{my-property}: #81F7D8;
}

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

lessc style.less style.css

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

style.css

.myclass {
   background-color: #81F7D8;
}

輸出

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

  • 將上述HTML程式碼儲存到less_variables_interpolation_properties.html檔案中。

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

LESS Variables Interpolation Properties
less_variables.htm
廣告
© . All rights reserved.