【发布时间】:2020-03-26 19:24:14
【问题描述】:
我正在尝试在网站上制作模态框,但它没有显示出来。模态框中的内容很好,但如果需要,我还附上内容的 CSS 代码。
document.getElementById('buttonL').addEventListener("click", function() {
document.querySelector('.bg-modal').style.display = "flex";
});
document.querySelector('.close').addEventListener("click", function() {
document.querySelector('.bg-modal').style.display = "none";
});
.bg-modal{
background-color: rgba(0, 0, 0, 0.5);
width: 100%;
height: 100%;
position: fixed;
display: none;
justify-content: center;
align-items: center;
bottom: 0px;
}
.modal-content{
width: 600px;
height: 300px;
background-color: white;
opacity: 1;
border-radius: 2px;
}
.modal-content h1{
align-items: center;
text-align: center;
margin-top: 40px;
font-family: 'Rubik', sans-serif;
}
.modal-content img{
float: left;
width: 160px;
margin-top: 20px;
margin-left: 60px;
}
.modal-content p{
float: right;
margin-top: 20px;
margin-right: 60px;
font-size: 16px;
}
.close {
position: relative;
float: right;
margin-right: 8px;
font-size: 32px;
color: #333;
background-color: none;
cursor: pointer;
}
<button id="buttonL" class="buttonLegal">LEGAL DETAILS</button>
<div class="bg-modal">
<div class="modal-content">
<div class="close">✖</div>
<h1>LEGAL DETAILS</h1>
<img src="someimagehere.jpg">
<p>some text here</p>
</div>
</div>
我搜索了整个互联网并尝试了很多方法,但仍然无法显示模态框。我想我的 Javascript 代码可能有错误,但我不确定。所以,我希望你能在这件事上帮助我。谢谢!
【问题讨论】:
-
它工作正常
-
在执行此代码之前,您可能会遇到任何控制台错误。
-
我已经在 sn-p 视图中添加了您的代码,没有进行任何更改,它工作正常
标签: javascript html css modal-dialog