Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add alpha channel to a given color

Tags:

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:

span.foo{     background-color: rgba(0,0,0,1); /*or whatever*/     color:white; }  span.foo:last-child{     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?

like image 292
manutenfruits Avatar asked Aug 31 '12 13:08

manutenfruits


People also ask

How do I add alpha to my background color?

Changing the opacity of the background color only To achieve this, use a color value which has an alpha channel—such as rgba. As with opacity , a value of 1 for the alpha channel value makes the color fully opaque. Therefore background-color: rgba(0,0,0,. 5); will set the background color to 50% opacity.

What is alpha channel of color?

The alpha channel (also called alpha planes) is a color component that represents the degree of transparency (or opacity) of a color (i.e., the red, green and blue channels). It is used to determine how a pixel is rendered when blended with another.

How do you color in Alpha?

2. Click "Color" from the menu bar and select "Color to Alpha." The Color to Alpha dialog window opens and shows a small preview of your image. The Color to Alpha feature allows you to choose a color in your image and make it transparent.


2 Answers

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: http://jsfiddle.net/YfSn7/30/

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.

like image 123
Anonymous Avatar answered Oct 05 '22 07:10

Anonymous


If you have Sass:

background-color: rgba(white, 0.5); 
like image 27
Brandon Dyer Avatar answered Oct 05 '22 07:10

Brandon Dyer