[英]Why modal-backdrop overlapped my popup modal even set !important and z-index? How to fix it?
I had a successful message popup.我有一个成功的消息弹出窗口。 Now I want to add a semi-transparent backdrop layer underneath with
rgba(0,0,0,0.5)
, that I used CSS ::before
.现在我想用
rgba(0,0,0,0.5)
在下面添加一个半透明的背景层,我使用了CSS ::before
。 But the backdrop ::before { rgba(0,0,0,0.5) }
seems to overlap my green popup, even when I set z-index
and background: !important
for the popup.但是背景
::before { rgba(0,0,0,0.5) }
似乎与我的绿色弹出窗口重叠,即使我设置了z-index
和background: !important
弹出窗口也是如此。
Here's the code I've tried这是我试过的代码
.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">×</button> </div>
You need to wrap the modal's content inside another extra wrapper div .modal-content
.您需要将模态的内容包装在另一个额外的包装器 div
.modal-content
。 The example from w3school .来自 w3school的例子。
Your code doesn't work as expected because z index not working with fixed positioning您的代码没有按预期工作,因为z 索引不适用于固定定位
Here's the working code, I changed a few lines of code from yours:这是工作代码,我从您的代码中更改了几行代码:
/* 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">×</button> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.