LESS - 對比度



描述

它設定元素中顏色的對比度,並改變明暗值之間的差異。它具有以下引數:

  • color − 它表示一個顏色物件。

  • dark − 這是一個可選引數,用於設定暗色。

  • light − 這是一個可選引數,用於設定亮色。

  • threshold − 這是一個可選引數,包含 0-100% 之間的百分比,並指定從暗色到亮色的過渡。

示例

以下示例演示了在 LESS 檔案中使用對比度顏色操作:

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

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

      <div class = "myclass2">
         <p>result :<br>#81F79F</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: contrast(hsl(80, 90%, 20%), #81F79F, #01DFA5, 30%);
   color:white;
}

您可以使用以下命令將 `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: #81F79F;
   color: white;
}

輸出

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

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

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

Less Contrast
less_color_operation.htm
廣告
© . All rights reserved.