Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

I do not want to inherit the child opacity from the parent in CSS

I do not want to inherit the child opacity from the parent in CSS.

I have one div which is the parent, and I have another div inside the first div which is the child.

I want to set the opacity property in the parent div, but I don't want the child div to inherit the opacity property.

How can I do that?
by

2 Answers

rahul07
Instead of using opacity, set a background-color with rgba, where 'a' is the level of transparency.

So instead of:

background-color: rgb(0,0,255); opacity: 0.5;

use

background-color: rgba(0,0,255,0.5);
sandhya6gczb
As others have mentioned in this and other similar threads, the best way to avoid this problem is to use RGBA/HSLA or else use a transparent PNG.

Login / Signup to Answer the Question.