简体   繁体   English

使用SCSS添加两个颜色值

[英]Adding two color values with SCSS

I am adding two color values in color attribute and subtracting two values in background color using SCSS. 我在color属性中添加了两个颜色值,并使用SCSS在背景颜色中减去了两个值。 It shows some third value. 它显示了一些第三值。 Is there any pattern/formula to add or subtract the colors? 是否有任何图案/公式可增加或减少颜色?

p{
  color: #ab00ff + #100abb; //bb0aff
  background-color: #ab00ff - #100abb; //9b0044
}

Colors in hexadecimal form are broken down into three components, each of which are independent of the other two. 十六进制形式的颜色分为三个分量,每个分量与其他两个分量无关。 A better way of understanding colors in hexadecimal form can be illuminated by the following spacing of the hex color: 通过十六进制颜色的以下间距,可以更好地理解十六进制颜色:

# RR GG BB

Where RR represents the red coloring, GG represents the green coloring, and BB represents the blue coloring. 其中RR代表红色, GG代表绿色, BB代表蓝色。

The important takeaway is to understand that when performing addition and subtraction between hexadecimal colors, an f value is a maximum color value and a 0 is a minimum color value. 重要的要点是要理解,当在十六进制颜色之间执行加减运算时, f值是最大颜色值,而0是最小颜色值。

In more detail, f in hexadecimal (base16) is the same as 16 in base10, whereas 0 in hex is the same as 0 in base10. 更详细地, f十六进制(base16)是相同的16中base10,而0的十六进制相同0在base10。

In your addition example, a is equivalent to 10 in base10, and 10 + 1 would be 11 in base10 and b in base16: 在您的附加示例中, a等于base10中的10 ,而10 + 1在base10中为11 ,在base16中为b

    v
  # ab 00 ff
+ # 10 0a bb
  -------
  # bb 0a ff
          ^^

For the calculation of the blue component, the result is ff , since the max color value is f (ie, f + any value is still f ). 对于蓝色分量的计算,结果为ff ,因为最大颜色值为f (即f + any value仍为f )。

In the subtraction example, the lowest value you can have is the absence of the color at 0 , so 0 - any value , in this case a , still results in 0 : 在减法示例中,可以拥有的最小值是0处没有颜色,因此0any value (在这种情况下为a )仍为0

  #ab 00 ff
- #10 0a bb
  -------
  #9b 00 44
       ^

Hope this makes sense. 希望这是有道理的。

For more information, see: https://en.wikipedia.org/wiki/Web_colors#Shorthand_hexadecimal_form 有关更多信息,请参见: https : //en.wikipedia.org/wiki/Web_colors#Shorthand_hexadecimal_form

Adding two colours together results in a new colour with each of its RGB values equal to the sum of the corresponding RGB input values. 将两种颜色加在一起会得到一种新颜色,其每个RGB值等于相应RGB输入值的总和。 This can be made clear by converting the colours into their RGB formats: 可以通过将颜色转换为RGB格式来弄清楚:

p {
    color: rgb(171, 0, 255) + rgb(16, 10, 187); // rgb(187, 10, 255)
    background-color: rgb(171, 0, 255) - rgb(16, 10, 187); // rgb(155, 0, 68)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM