开发者

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

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

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

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜