我正在研究模态框。
当我制作单独的 html 和 css 文件来测试它时,它工作得很好。问题是当我将该代码放入我正在处理的网页的 html 和 css 中时,模态框没有出现,唯一显示的是模态容器的深色覆盖。
帮助将不胜感激。谢谢。
仅模态
const open = document.getElementById("open");
const modalContainer = document.getElementById("modal-container");
const close = document.getElementById("close");
open.onclick = function() {
modalContainer.style.display = "block";
};
close.onclick = function() {
modalContainer.style.display = "none";
};
.modal-container {
background-color: rgba(0, 0, 0, 0.4);
position: fixed;
top: 0;
left: 0;
z-index: 1;
width: 100%;
height: 100%;
overflow: auto;
display: flex;
justify-content: center;
align-items: center;
font-family: fantasy;
display: none;
}
.modal {
background-color: whitesmoke;
width: 35%;
height: 90%;
margin: 5% auto;
padding: 20px 40px;
box-shadow: 5px 5px 5px gray;
border-radius: 10px;
}
.modal span {
display: flex;
justify-content: flex-end;
margin-right: -15px;
cursor: pointer;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="modal.css">
</head>
<body>
<button id="open" onclick="openModal()">open modal</button>
<div class="modal-container" id="modal-container">
<div class="modal">
<span id="close">×</span>
<h1>Swimming Pools (Drank)</h1>
<hr>
<p>Pour up, drank, head shot, drank <br> Sit down, drank, stand up, drank <br> Pass out, drank, wake up, drank <br> Faded, drank, faded, drank</p>
</div>
</div>
</body>
</html>
白猪掌柜的
相关分类