So I'm trying to create a lightbox like feel. I created a #blackout
div and an #enlargedBOX
div.
The #blackout
div has it's opacity set to 90%, because I want the background website to show through just a bit, however i do NOT want my #enlargedBOX
div to use that same opacity. It seems that #blackout
forces its own opacity onto anything within itself. How can i stop that?
<div id="blackout">
<div id="enlargedBOX">
<img src="" width="500" height="500" border="0" />
</div>
</div>
Here's a jsFiddle
You'll see that the RED background shows through on the white #enlargedBOX
div.
Note: When using the opacity property to add transparency to the background of an element, all of its child elements become transparent as well. This can make the text inside a fully transparent element hard to read.
Answer: Use the CSS RGBA colors There is no CSS property like "background-opacity" that you can use only for changing the opacity or transparency of an element's background without affecting its child elements.
Opacity is not inherited, but because the parent has opacity that applies to everything within it. You cannot make a child element less transparent than the parent, without some trickery. Values are a number from 0 to 1 representing the opacity of the channel (the “alpha” channel).
The opacity property specifies the opacity/transparency of an element.
Just use rgba()
- DEMO
#blackout {
position:absolute;
top:0px;
left:0px;
height:100%;
width:100%;
overflow:auto;
z-index:100;
background: rgba(0, 0, 0, .9);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With