当前位置: 首页 > 文档资料 > Less 入门教程 >

mix

优质
小牛编辑
125浏览
2023-12-01

描述 (Description)

它用于混合两种颜色和不透明度。 它有以下参数 -

  • color1 - 它表示一个颜色对象。

  • color2 - 它代表一个颜色对象。

  • weight - 它是一个可选参数,通过提供两种颜色之间的百分比平衡点来指定元素的权重。

例子 (Example)

以下示例演示了在LESS文件中使用混合颜色操作 -

<html>
   <head>
      <title>Mix</title>
      <link rel = "stylesheet" type = "text/css" href = "style.css"/>
   </head>
   <body>
      <h2>Example of Mix Color Operation</h2>
      <div class = "myclass">
         <p>Mixed color :<br>#b0897d</p>
      </div>
   </body>
</html>

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

style.less

.myclass{
   height:100px;
   width:100px;
   padding: 30px 0px 0px 25px;
   background-color: mix(#b361b1, #acb148, 50%);
   color:white;
}

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

lessc style.less style.css

执行上面的命令; 它将使用以下代码自动创建style.css文件 -

style.css

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

输出 (Output)

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

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

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

少混合