less学习——Color 函数

简介: LESS 提供了一系列的颜色运算函数. 颜色会先被转化成 HSL 色彩空间, 然后在通道级别操作:lighten(@color, 10%); // return a color which is 10% *li...

LESS 提供了一系列的颜色运算函数. 颜色会先被转化成 HSL 色彩空间, 然后在通道级别操作:

lighten(@color, 10%);     // return a color which is 10% *lighter* than @color
darken(@color, 10%);      // return a color which is 10% *darker* than @color

saturate(@color, 10%);    // return a color 10% *more* saturated than @color
desaturate(@color, 10%);  // return a color 10% *less* saturated than @color

fadein(@color, 10%);      // return a color 10% *less* transparent than @color
fadeout(@color, 10%);     // return a color 10% *more* transparent than @color
fade(@color, 50%);        // return @color with 50% transparency

spin(@color, 10);         // return a color with a 10 degree larger in hue than @color
spin(@color, -10);        // return a color with a 10 degree smaller hue than @color

mix(@color1, @color2);    // return a mix of @color1 and @color2
AI 代码解读

使用起来相当简单:

@base: #f04615;

.class {
  color: saturate(@base, 5%);
  background-color: lighten(spin(@base, 8), 25%);
}
AI 代码解读

你还可以提取颜色信息:

hue(@color);        // returns the `hue` channel of @color
saturation(@color); // returns the `saturation` channel of @color
lightness(@color);  // returns the 'lightness' channel of @color
AI 代码解读

如果你想在一种颜色的通道上创建另一种颜色,这些函数就显得那么的好用,例如:

@new: hsl(hue(@old), 45%, 90%);
AI 代码解读

@new 将会保持 @old的 色调, 但是具有不同的饱和度和亮度.

个人博客: 付博瀚个人博客1 付博瀚个人博客2

fbh
+关注
目录
打赏
0
0
0
0
1
分享
相关文章
|
10月前
|
前景色[color]
前景色[color]。
64 0
Codeforces Round #748 (Div. 3) F - Red-Black Number (记忆化搜索)
Codeforces Round #748 (Div. 3) F - Red-Black Number (记忆化搜索)
109 0
html+css实战96-计算border
html+css实战96-计算border
164 0
html+css实战96-计算border
1054. The Dominant Color (20)
Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel.
1075 0

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等