滚动不适用于固定和绝对位置,我不知道还要添加什么
.modal-overlay {
z-index:9999;
opacity: 1;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: flex;
align-items: center;
justify-content: center;
background: rgba(77, 77, 77, .7);
transition: all .4s;
width:100%;
overflow-x: hidden;
overflow-y: scroll;
}
.modal-backgroundparent {
display:flex;
align-items:center;
justify-content:center;
}
.modal-background {
z-index:10000;
width: 350px;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #fff;
border-radius: 10px;
}
来自 Modal 的 HTML 模板
<div class='modal-overlay'>
<div class='modal-backgroundparent'>
<div class='modal-background'>
<img src="img/images.png">
</div>
</div>
</div>
“模态背景”不需要像父级那样“固定”定位。