Question

In LESS there is a function that computes the average of two colors. For example,

average(#ff6600, #666666);

outputs #b36633.

But this function takes equal parts of color1 and color2. Is there a way to say, take X% of color1 and (1-X)% of color2 and average them?

Of course, no such function exists. But maybe through the help of some other functions, we can achieve a weighted average?

EDIT: I think using mix() may take care of it, since you can specify a percentage proportion:

mix(#ff6600, #666666, 70%)

However, I'm not sure if mix(color1, color2, 50%) would achieve the same effect as average(color1, color2) for any color1, color2.

Was it helpful?

Solution

mix(#ff6600, #666666, 70%) for the last parameter 0% will result in the first color we stated (which in this case ff6600) while 100% will do the 666666.

so in your case mix(color1, color2, 70%) the output is 70% of color2 plus 30% of color1.

the default is 50% if you leave the parameter empty!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top