Search code examples
cssopacityrgba

PHP generated semi transparent background color using opacity affects text


I'm working with a background-color which should be 70% transparent, but I have many limitations:

  1. I can't use RGBa or HSLA (I'm getting the colors from a PHP Content Management System) as Hex
  2. The background color is dynamic - I can't use an image
  3. when I use opacity, the text is affected as well making it unreadable.

I'm sure the only option I have is changing my PHP code to generate RGBa colors instead, but asking, do you see any other solution?

enter image description here


Solution

  • You can assign a pseudo element to the containing div. Like so:

    .container:before{
     opacity:0.5;
    }
    

    You could also convert your hex value to RGB and then use that: RGB to Hex and Hex to RGB