1

I just applied a opacity to a #wrapper div with a solid color:

jQuery("#wrapper").css({ opacity: 0.5 })

This works nicely, but I don't want their children divs to inherit the opacity. How do I avoid this behavior without using PNG transparency hacks?

2
  • 1
    The short answer is you can't. You will have to place the contents in a different container. Commented Feb 10, 2011 at 14:39
  • If you want a little bit of transparency on the background of the #wrapper, try use rgba() instead of solid color. Commented Apr 23, 2014 at 17:48

2 Answers 2

6

Opacity is always inherited by descendant elements. There are no way to avoid it, and it isn't due to jQuery, but the way opacity works.

Sign up to request clarification or add additional context in comments.

Comments

1

Clone the element (and children) and get the offsets. Then in the original element, hide all the inner elements. Now set the opacity. With the cloned element, place it on top of the original element (using position and the offsets), but this time hide the background to the cloned element.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.