0

I have this div :

<div style="background-color: rgba(219, 70, 117, 0.83);">

I would like to change the rgba with hexa color. But I want to conserve the transparent (0.83).

How can I do that ?

This is because I have a scope in my JS how give me only an hexa value.

Evan Porter
  • 2,987
  • 3
  • 32
  • 44

2 Answers2

0

You can use the following function:

function convertHex(hex, opacity){
    hex = hex.replace('#','');
    r = parseInt(hex.substring(0,2), 16);
    g = parseInt(hex.substring(2,4), 16);
    b = parseInt(hex.substring(4,6), 16);

    result = 'rgba('+r+','+g+','+b+','+opacity+')';
    return result;
}

Usage:

var rgba = convertHex('#CCCCCC', 0.83);

With some more explanation on your specific issue I may be able to assist you in better alternatives.

Ismail RBOUH
  • 10,292
  • 2
  • 24
  • 36
0

Maybe you can use opacity in your context:

background-color:#AAAAAA;
opacity: 0.83;
filter: alpha(opacity=83); /* For IE8 and earlier */

http://www.w3schools.com/css/css_image_transparency.asp

StegSchreck
  • 320
  • 4
  • 18