影响子元素的不透明度CSS

发布于 2025-01-05 17:03:47 字数 241 浏览 4 评论 0原文

我正在尝试在用户禁用 javascript 时实现错误消息。我为我当前的工作创建了一个 jsfiddle 。我有 2 个 div 层,一个覆盖整个页面,另一个在上面显示警告消息,但不透明度设置影响覆盖层也会影响警告消息。我尝试过使用之前问题中的技术,但无法使其发挥作用。谁能帮助我吗?

http://jsfiddle.net/xcPcv/

I am trying to implement an error message when user has disabled javascript. I have created a jsfiddle for my current work. I have 2 div layers one covering the whole page and an another one on top of that to show the warning message, but the opacity settings affects for the cover layer affects the warning message also. I have tried using the techniques from previous questions but I could not make it work. Can anyone help me?

http://jsfiddle.net/xcPcv/

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

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

发布评论

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

评论(3

送你一个梦 2025-01-12 17:03:47

只需将消息移到褪色容器之外...

从:

<div id="fadeMe">
    <div id="center">You have javascript disabled.</div>
</div>

到:

<div id="fadeMe">
</div>
<div id="center">You have javascript disabled.</div>

http://jsfiddle.net/xcPcv/7/

Just move the message outside of the faded container ...

From:

<div id="fadeMe">
    <div id="center">You have javascript disabled.</div>
</div>

To:

<div id="fadeMe">
</div>
<div id="center">You have javascript disabled.</div>

http://jsfiddle.net/xcPcv/7/

风轻花落早 2025-01-12 17:03:47

使用 rgba(0,0,0,.75) 作为背景,而不是不透明度:

http://jsfiddle。净/xcPcv/9/

Instead of opacity, use rgba(0,0,0,.75) for the background:

http://jsfiddle.net/xcPcv/9/

会傲 2025-01-12 17:03:47

问题是不透明度适用于所有包含的(子)元素,而不仅仅是您要应用

    opacity

的元素。这样做的副作用是进一步的不透明度设置将是父不透明度的那一部分。

在您的情况下,您只需将弹出 div 移到 fadeMe div 之外即可

    <div id="fadeMe"></div>
    <div id="center">You have javascript disabled.</div>

The issue is that opacity applies to all contained (child) elements, not just the element you are applying

    opacity

to. A side effect of this is that a further opacity setting will be that fraction of the parent opacity.

In your case you need to do nothing else but move the popup div outside the fadeMe div

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