Use HEX or RGBA

别说谁变了你拦得住时间么 提交于 2019-12-06 09:33:06

Both should be compatible with any standards-compliant browser.

Edit: There might be some buggy behavior in IE (suprise!): http://css-tricks.com/ie-background-rgb-bug/

When using RGBA, I believe the correct syntax is to use R, G, B values. Hence the name. I've not tried using Hex instead, that may result in unexpected behavior.

In terms of browser compatibility, Hex and RGB are pretty much same/same.

Form a browser compatibility stand point there is nearly no real difference in any modern-ish Browser.

Where you can, I'd go with HEX. Shorter, one string and therefore easier to copy to third party programs (e.g. Photoshop, etc.) and also you don't have the IE bug mentioned by Erty.

I tend to use RGBA only where I need alpha, on all other elements I use HEX.

Danield

You could actually (almost) always use Hex.

Even when you need alpha there's a way to convert the RGBA value to an equivalent Hex value as long as the background color (under the element with rgba) is a single solid color.

The algorithm for this conversion is here.

Source => Target = (BGColor + Source) =
Target.R = ((1 - Source.A) * BGColor.R) + (Source.A * Source.R)
Target.G = ((1 - Source.A) * BGColor.G) + (Source.A * Source.G)
Target.B = ((1 - Source.A) * BGColor.B) + (Source.A * Source.B)

( I've actually used it a few times, and it works well for me.

As mentioned in previous answers, the gain over here is that the intended RBGA color will look like it should in ie8 and down.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!