LESS - 颜色混合强光函数



描述

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

参数

  • color1 − 要覆盖的颜色对象。

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

返回值

颜色

示例

以下示例演示了在 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.htm
广告

© . All rights reserved.