jQuery(“#wrapper”).css({ 不透明度: 0.5 })

发布于 2024-10-16 17:00:34 字数 207 浏览 3 评论 0原文

我刚刚对纯色的 #wrapper div 应用了不透明度:

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

这很好用,但我不希望他们的子 div继承不透明度。如何在不使用 PNG 透明度 hack 的情况下避免这种行为?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

囍孤女 2024-10-23 17:00:34

不透明度始终由后代元素继承。没有办法避免它,这不是由于 jQuery,而是由于不透明度的工作方式。

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.

本宫微胖 2024-10-23 17:00:34

克隆元素(和子元素)并获取偏移量。然后在原始元素中,隐藏所有内部元素。现在设置不透明度。对于克隆的元素,将其放置在原始元素的顶部(使用位置和偏移量),但这次隐藏克隆元素的背景。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文