如何在CSS中获取两种重叠颜色的颜色代码?

huangapple go评论72阅读模式
英文:

How to get the color code of two overlapping colors in css?

问题

Sure, here's the translated portion of your text:

我有两种颜色:#FFF8F6#AD3300#AD3300 也可以写成 rgba(173, 51, 0, 1)
我想要在第二种颜色(透明度为14%)覆盖在第一种颜色的顶部,以获得第三种颜色。所以在 #FFF8F6 下方,在 rgba(173,51,0, 0.14) 上方。

是否可以使用 SASSCSS 的某个函数来获取这个颜色代码(位于带有红色边框的框中)?

对于 background 属性,您可以使用以下代码:

linear-gradient(0deg, rgba(173, 51, 0, 0.14), rgba(173, 51, 0, 0.14)), #FFF8F6;

对于 color 属性,您想要如何处理?

英文:

I have two colors: #FFF8F6 and #AD3300. #AD3300 can also be written rgba(173, 51, 0, 1).
I would like to overlay the second color (at 14% opacity) on top of the first to get a third color. So below #FFF8F6 and above rgba(173,51,0, 0.14).

如何在CSS中获取两种重叠颜色的颜色代码?

Is it possible to get this color code (the one in the box with the red border) with some function of SASS or CSS?

For the backgroud I can use:

linear-gradient(0deg, rgba(173, 51, 0, 0, 0.14), rgba(173, 51, 0, 0.14)), #FFF8F6;

for the color property how can I do it?

答案1

得分: 1

是的,原来您可以使用原始CSS来实现这个效果!

您可以使用color-mix()函数。

我使用了下面这行代码来计算颜色组合:

background: color-mix(in srgb, #FFF8F6, #AD3300 14%);

#FFF8F6作为您的第一种颜色,将#AD3300 14%作为您的第二种颜色,其中颜色给定并指定了其不透明度。

我尝试使用rgba(173, 51, 0, 0.14),但混合效果不对。

注意,这在当前浏览器中得到广泛支持,但有以下几个例外:

  1. Opera(实验性功能)
  2. Opera Android
  3. Samsung Internet
英文:

Yes, it turns out you can with raw CSS!

You can use color-mix()

I used the line below to calculate the color combination:

background: color-mix(in srgb, #FFF8F6, #AD3300 14%);

With #FFF8F6 as youyr first color, and #AD3300 14% as your second color, where it is broken down by the color given and its opacity.

I tried using rgba(173, 51, 0, 0.14) but the mix didn't come out right.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.box {
  height: 200px;
  width: 200px;
  position: absolute;
  /* border: 1px solid gray; */
}

.box1 {
  top: 50px;
  left: 50px;
  background: #FFF8F6;
}

.box1 div {}

.box2 {
  top: 150px;
  left: 150px;
  background: #AD330024;
}

.box2 div {
  margin: 160px 0 0 0;
  text-align: right;
}

.box3 {
  height: 100px;
  width: 100px;
  top: 50px;
  left: 250px;
  background: color-mix(in srgb, #FFF8F6, #AD3300 14%);
}

.box3 div {
  text-align: right;
}

<!-- language: lang-html -->

&lt;div class=&quot;box box1&quot;&gt;
  &lt;div&gt;#FFF8F6&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;box box2&quot;&gt;
  &lt;div&gt;#AD330024&lt;br/&gt;(rgba(173, 51, 0, 0.14))&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;box box3&quot;&gt;
  &lt;div&gt;color-mix&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

Note also that this is widely supported with the current exceptions being:

  1. Opera (experimental feature
  2. Opera Android
  3. Samsung Internet

huangapple
  • 本文由 发表于 2023年5月24日 17:33:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76322073.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定