Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the background colour's opacity in CSS [duplicate]

I have a PNG file which I give a background colour to its transparent areas, but I would like to make the background colour a bit transparent, like opacity. Here is my code so far:

social img{     opacity:0.5; } .social img:hover {     opacity:1;     background-color:black; } 
like image 533
Alex Jj Avatar asked Jun 02 '13 15:06

Alex Jj


People also ask

How do I change the opacity of a background in CSS?

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.

How can I change the opacity of background color in CSS without affecting text?

The percentage of opacity is calculated as Opacity% = Opacity * 100 To set the opacity only to the background and not the text inside it. It can be set by using the RGBA color values instead of the opacity property because using the opacity property can make the text inside it fully transparent element.

How do I reduce background opacity?

Approach: We can use the opacity property in CSS which is used to change the opacity of an element. The value of the property can be set in a range of 0 to 1, where “0” is fully transparent and “1” is opaque. Any decimal value can be used in between to set the opacity accordingly.

How do you add black opacity in CSS?

You have to add the following CSS property to achieve the transparency levels. This sets the background-color of an element to black with 50% opacity. The last value in an rgba value is the alpha value. An alpha value of 1 is equal to 100% opacity, and 0.5 (or .


2 Answers

background: rgba(0,0,0,.5); 

you can use rgba for opacity, will only work in ie9+ and better browsers

like image 63
bob Avatar answered Sep 28 '22 05:09

bob


Use RGBA like this: background-color: rgba(255, 0, 0, .5)

like image 23
bookcasey Avatar answered Sep 28 '22 05:09

bookcasey