Sass語言具有稱爲變暗的函數,它具有兩個參數:您想要使顏色變暗的顏色和百分比。我只知道原始顏色和顏色。我如何確定傳遞給darken函數的百分比值以及原始顏色?如果我有原始顏色和變暗的顏色,我如何確定在Sass中使用了多少百分比使其變暗?
darken(#e8e8e8, ???) // returns #c1c1c1
Sass語言具有稱爲變暗的函數,它具有兩個參數:您想要使顏色變暗的顏色和百分比。我只知道原始顏色和顏色。我如何確定傳遞給darken函數的百分比值以及原始顏色?如果我有原始顏色和變暗的顏色,我如何確定在Sass中使用了多少百分比使其變暗?
darken(#e8e8e8, ???) // returns #c1c1c1
對於變暗(也可能減輕太),你可能需要計算兩種顏色的明度值之間的差異:
@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;
}
您可以使用rgba()
其中RGB是REG,綠色,藍色和 '一' 是阿爾法。您可以使用alpha而不是百分比。
我不需要alpha –
我需要一個沒有alpha的普通顏色 –
你問如何以編程方式定義一種顏色需要變暗以導致另一種顏色的百分比?它是否必須使用非單色顏色?相關:http://stackoverflow.com/questions/24647881/how-to-get-desired-color-from-base-color-in-sass/24662251 – KatieK