Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper use of opacity with nested DIVs? [duplicate]

Tags:

css

opacity

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.

like image 682
ipixel Avatar asked Feb 25 '13 21:02

ipixel


People also ask

When using the opacity property to add transparency to the background of an element all of its child elements inherit the same transparency?

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.

How do you change opacity without affecting children's elements?

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.

Can you not inherit an opacity from a parent?

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).

Which property specifies the opacity transparency of an element?

The opacity property specifies the opacity/transparency of an element.


1 Answers

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);
}
like image 91
Zoltan Toth Avatar answered Sep 22 '22 15:09

Zoltan Toth