最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Add opacity to hex representation of color - Stack Overflow

programmeradmin1浏览0评论

I have a color code, for example #EB5757 which is a kind of red. I want to add opacity to it 0.15 or 15%. After looking on this question I saw in the accepted answer that for 15% one must add 26 at the beginning.

So I did it: #26EB5757 but now the resulted color is not a red with opacity but a green. I'm using this in Javascript/React if this information is useful.

style = {backgroundColor: '#26EB5757'}

Any ideas on how to set that original red color to be opaque?

I have a color code, for example #EB5757 which is a kind of red. I want to add opacity to it 0.15 or 15%. After looking on this question I saw in the accepted answer that for 15% one must add 26 at the beginning.

So I did it: #26EB5757 but now the resulted color is not a red with opacity but a green. I'm using this in Javascript/React if this information is useful.

style = {backgroundColor: '#26EB5757'}

Any ideas on how to set that original red color to be opaque?

Share Improve this question asked Apr 28, 2020 at 11:42 Leo MessiLeo Messi 6,25622 gold badges80 silver badges155 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

8 digit hexadecimal color notation in CSS has the following format:

#RRGGBBAA

RR - red
GG - green
BB - blue
AA - alpha

You should use:

#EB575726 (for your 15% red)

I guess you can use convertor to get actual RGB representation of that HEX. You may try this one

Then you can simple add your opacity into rgba like this use backgroundColor: rgba(235,87,87, 0.15)

发布评论

评论列表(0)

  1. 暂无评论