英文:
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)
上方。
是否可以使用 SASS 或 CSS 的某个函数来获取这个颜色代码(位于带有红色边框的框中)?
对于 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)
.
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)
,但混合效果不对。
注意,这在当前浏览器中得到广泛支持,但有以下几个例外:
- Opera(实验性功能)
- Opera Android
- 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 -->
<div class="box box1">
<div>#FFF8F6</div>
</div>
<div class="box box2">
<div>#AD330024<br/>(rgba(173, 51, 0, 0.14))</div>
</div>
<div class="box box3">
<div>color-mix</div>
</div>
<!-- end snippet -->
Note also that this is widely supported with the current exceptions being:
- Opera (experimental feature
- Opera Android
- Samsung Internet
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论