gpt4 book ai didi

html - 为什么模态背景与我的弹出模态重叠甚至设置了 !important 和 z-index?如何解决?

转载 作者:行者123 更新时间:2023-11-28 16:49:54 24 4
gpt4 key购买 nike

我有一个成功的消息弹出窗口。现在我想在 rgba(0,0,0,0.5) 下面添加一个半透明背景层,我使用了 CSS::before。但是背景 ::before { rgba(0,0,0,0.5) } 似乎与我的绿色弹出窗口重叠,即使我设置了 z-index背景:弹出窗口的 !important

这是我试过的代码

.alertMessageModal{ width:auto; height:auto; border-radius:10px; display:inline-block; position:fixed; top:20px; right:25px; color:#fff; padding:10px 15px; padding-bottom:15px; z-index:100; background:green !important;}
.alertMessageModal::before{content:''; position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0, 0, 0, 0.5); z-index:-100;}
.alertMessageModal .modal-title{ font-size:15px; float:left; line-height:18px;}
.alertMessageModal .close{ float:right; margin-left:10px; line-height: 15px; color:#fff;}
<div class="alertMessageModal bg-success">
<h4 class="modal-title">Your message has been successfully sent</h4>
<button type="button" class="close">&times;</button>
</div>

最佳答案

您需要将模态框的内容包装在另一个额外的包装器 div .modal-content 中。 example from w3school .

您的代码没有按预期工作,因为 z index not working with fixed positioning

这是工作代码,我从你的代码中更改了几行:

/* renamed from .alertMessageModel::before */
.alertMessageModal {
content: '';
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: -100;
}
/* renamed from .alertMessageModal */
.modal-content {
width: auto;
height: auto;
border-radius: 10px;
display: inline-block;
position: fixed;
top: 20px;
right: 25px;
color: #fff;
padding: 10px 15px;
padding-bottom: 15px;
z-index: 100;
background: green !important;
}
.alertMessageModal .modal-title {
font-size: 15px;
float: left;
line-height: 18px;
}
.alertMessageModal .close {
float: right;
margin-left: 10px;
line-height: 15px;
color: #fff;
}
<div class="alertMessageModal bg-success">

<!-- added an extra div -->
<div class="modal-content">
<h4 class="modal-title">Your message has been successfully sent</h4>
<button type="button" class="close">&times;</button>
</div>

</div>

关于html - 为什么模态背景与我的弹出模态重叠甚至设置了 !important 和 z-index?如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59442360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com