LESS - 漸變



描述

它用於為選定元素設定顏色的透明度。它具有以下引數:

  • 顏色 - 它表示顏色物件。

  • 數量 - 它包含 0-100% 之間的百分比。

示例

以下示例演示了在 LESS 檔案中使用漸變顏色運算:

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

   <body>
      <h2>Example of Fade Color Operation</h2>
      <div class = "myclass1">
         <p>color :<br>#426105</p>
      </div><br>

      <div class = "myclass2">
         <p>result :<br>rgba(66, 97, 5, 0.1)</p>
      </div>
   </body>
</html>

接下來,建立 _style.less_ 檔案。

style.less

.myclass1 {
   height:100px;
   width:100px;
   padding: 30px 0px 0px 25px;
   background-color: hsl(80, 90%, 20%);
   color:white;
}

.myclass2 {
   height:100px;
   width:100px;
   padding: 30px 0px 0px 25px;
   background-color: fade(hsl(80, 90%, 20%), 10%);
   color:black;
}

您可以使用以下命令將 _style.less_ 編譯為 _style.css_:

lessc style.less style.css

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

style.css

.myclass1 {
   height: 100px;
   width: 100px;
   padding: 30px 0px 0px 25px;
   background-color: #426105;
   color: white;
}

.myclass2 {
   height: 100px;
   width: 100px;
   padding: 30px 0px 0px 25px;
   background-color: rgba(66, 97, 5, 0.1);
   color: black;
}

輸出

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

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

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

Less Fade
less_color_operation.htm
廣告