manutenfruits manutenfruits - 12 days ago 4x
CSS Question

Add alpha channel to a given color

I have a couple of next to each other that I want to style with CSS. I want to apply a wide variety of colors for the background, but I want the lower one to be the same color with reduced opacity, so I thought of this:{
background-color: rgba(0,0,0,1); /*or whatever*/
background-color: rgba(*,*,*,0.5); /*just an example*/

So I want to change the opacity of the already defined background without affecting the opacity of the text just by using CSS3.

Is this possible?


I believe there is no way to do it.

Css is very limited by itself, and there isn't much you can do with it.

The only way you could add opacity is:

opacity: 0.5

But the above would also affect the text itself, not only background.

However, you could wrap it in way that would separate the background blocks from the text, so that would keep the color of the text untouched.

EDIT: See the fiddle:

But that may look somewhat ridiculous, so I wouldn't much advice using it.

Guess you would have to accept that this is impossible, if you do actually want to make things simpler instead of over-complicating them.