Colors 如果我有原始颜色和变暗的颜色,我如何确定在Sass中用于使其变暗的百分比?

Colors 如果我有原始颜色和变暗的颜色,我如何确定在Sass中用于使其变暗的百分比?,colors,sass,Colors,Sass,Sass语言有一个名为darken的函数,它接受两个参数:颜色和要使颜色变暗的百分比。我只知道原始颜色和结果颜色。如何确定与原始颜色一起传递给变暗函数的百分比值 darken(#e8e8e8, ???) // returns #c1c1c1 您可以使用rgba,其中rgb为reg、绿色、蓝色,“a”为alpha。您可以使用alpha而不是percentage。对于变暗和可能变亮,您需要计算两种颜色的亮度值之间的差异: @function color-difference($c1, $c2) {

Sass语言有一个名为darken的函数,它接受两个参数:颜色和要使颜色变暗的百分比。我只知道原始颜色和结果颜色。如何确定与原始颜色一起传递给变暗函数的百分比值

darken(#e8e8e8, ???) // returns #c1c1c1

您可以使用rgba,其中rgb为reg、绿色、蓝色,“a”为alpha。您可以使用alpha而不是percentage。

对于变暗和可能变亮,您需要计算两种颜色的亮度值之间的差异:

@function color-difference($c1, $c2) {
  $c1: lightness($c1);
  $c2: lightness($c2);
  @return max($c1, $c2) - min($c1, $c2);
}

$color1: #e8e8e8;
$color2: #c1c1c1;

.foo {
  // guessed the percentage manually
  test: darken($color1, 15.25%);
  // check our percentage
  test: color-difference($color1, $color2);
  // do we get the same result?
  test: darken($color1, color-difference($color1, $color2));
}
输出:

.foo {
  test: #c1c1c1;
  test: 15.2941176471%;
  test: #c1c1c1;
}

我需要一种没有字母的普通颜色。你是在问如何通过编程定义一种颜色需要变暗以产生另一种颜色的百分比吗?它必须使用非单色颜色吗?相关的: