views:

25

answers:

1

I'm writing styles for a page where I'd like to use rgba colors on the background of some list items. I've used the CSS background property along with rgba(146,138,118,.4) to define my transparent background color.

Now I'm trying to cover my bases with IE support by using the technique of an ms-filter as described in this article. (see heading "...and RGBA for all.")

The trouble is apparently the MS-filter requires you to use some type of hybrid between RGBA and Hex where the alpha transparency value is translated to a number between 00 and FF. See this description page from Microsoft for reference.

So the trouble is I can't figure out how on earth to properly convert my value from RGBA to that hex/rgba hybrid method. Can anybody point me to some good reference material on this? Please don't just give me the correct value - that does me no good outside of that color. I need to understand the how behind it, thanks.

+1  A: 

Translating an rgba alpha to the gradient filter format is very simple. It's a mapping from the interval [0, 1] to the interval [0, 255], represented in hex. To do the conversion, then, just multiply by 255 and convert to hex. For example, opacity in rgba(rr, gg, bb, 0.5) ends up as 7F (or 80, if you're rounding up):

0.5 * 255 = 127.5 (base 10)
127 (base 10) = 7F (base 16)

I assume you're not asking about how to convert between base 10 and base 16.

Matt Ball
can you please provide a reference for your answer?
JAG2007
@JAG2007: what do you mean, like a third-party website? I didn't use one. This is based on my experience with standardized CSS (e.g., `rgba` color notation) and Microsoft's `filter`s. Or are you looking for more detail?
Matt Ball
Yeah, just some where I can learn more about Hex and all the base mathematics. But nm, I'll just google it. Thanks!
JAG2007