LESS - 颜色混合 Hardlight 函数

说明

hardlight 函数的工作原理与 overlay 类似,但颜色的作用相反。它使用第二个参数执行 overlay() 函数,以确定是否应执行乘法或屏幕操作。

参数

  • color1 − 要 overlay 的颜色对象。

  • color2 −基础颜色对象是决定结果颜色变亮或变暗的决定性颜色。

返回

color

示例

以下示例演示了在 LESS 文件中使用 hardlight 函数 −

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

   <body>
      <h2>Hardlight Function</h2>
      <div class = "color1">
         <p>(color1) <br> #ff6600</p>
      </div><br>
      
      <div class = "color2">
         <p>(color2) <br> #0000ff</p>
      </div><br>
      
      <div class = "res">
         <p>(result) <br> #0000ff</p>
      </div>
   </body>
</html>

接下来,创建 style.less 文件。

style.less

.color1 {
   width: 100px;
   height: 100px;
   background-color: #ff6600;
}

.color2 {
   width: 100px;
   height: 100px;
   background-color: #0000ff;
}

.res {
   width: 100px;
   height: 100px;
   background-color: hardlight(#ff6600, #0000ff);
}

p {
   padding: 30px 0px 0px 25px;
   color: white;
}

您可以使用以下命令将 style.less 编译为 style.css

lessc style.less style.css

执行上述命令,它将自动使用以下代码创建 style.css 文件 −

style.css

.color1 {
   width: 100px;
   height: 100px;
   background-color: #ff6600;
}

.color2 {
   width: 100px;
   height: 100px;
   background-color: #0000ff;
}

.result {
   width: 100px;
   height: 100px;
   background-color: #0000ff;
}

p {
   padding: 30px 0px 0px 25px;
}

输出

按照以下步骤查看上述代码的工作原理 −

  • 将上述代码保存在 color_blending_hardlight.html 文件中。

  • 在浏览器中打开此 HTML 文件,将显示以下输出。

Less Color Blending Functions

less_color_blending_functions.html