Reputation: 311
I use this CSS for create opacity in background of div:
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
The problem in my case is that this way changes the color of font inside of div and the border color of div. Are there any alternatives that don't change the font's color?
Upvotes: 0
Views: 346
Reputation: 28437
When setting opacity, it is set for the whole div. If you want only want to make the background slightly transparent, you'll have to use rgba!
Example:
div {background-color: rgba(0, 0, 0, 0.5);} /* Black rgb(0,0,0) + 0.5 opacity */
div {background-color: rgba(255, 255, 255, 0.7);} /* White rgb(255,255,255) + 0.7 */ opacity
Ofcourse you have to integrate the background color that you had into the rgba code. The first three numbers are the normal red green blue values and the last one is the opacity (from 0 to 1).
Here is a useful tool to convert HEX values (like #ffffff
) to rgba(a) values!
Upvotes: 2
Reputation: 6156
.myelement {
background: rgba(200, 54, 54, 0.5);
}
For browsers support click here
.myelement {
background: rgba(200, 54, 54, 0.5);
-pie-background: rgba(200, 54, 54, 0.5);
behavior: url(PIE.htc);
}
Upvotes: 0
Reputation:
You can set opacity for background color:
background-color: rgba(0, 0, 0, 0.5);
See this example: http://jsfiddle.net/eaAmP/
Upvotes: 0