简体   繁体   English

如何在 HTML 中重叠两个 div(登录时的成功消息)?

[英]How to overlap two divs in HTML (success message when logged in)?

I am building a little login page and when successfully logged in I want a massage to pop up (not an alert).我正在构建一个小的登录页面,成功登录后,我希望弹出一个按摩(不是警报)。 I just want to have that message in the center of the page after I logged in.我只想在登录后在页面中央显示该消息。

Is there a way to implement that easily?有没有办法轻松实现?

picture of the website now现在网站的图片

This little message window should be in the middle of the page这个小消息窗口应该在页面的中间

I would call this a modal.我称之为模态。

 const overlay = document.querySelector("#overlay"); const button = document.querySelector("#button"); const closeButton = document.querySelector(".close"); button.onclick = () => { overlay.style.display = "grid"; } closeButton.onclick = () => { overlay.style.display = ""; } window.onclick = (e) => { if (e.target === overlay) { overlay.style.display = ""; } }
 .overlay { position: fixed; display: none; z-index: 999; left: 0; top: 0; width: 100vw; height: 100vh; background-color: rgba(100,100,100,0.4); } .modal { background-color: #fff; margin: auto; padding: 1em; border: 1px solid; width: 80vw; } .close { float: right; font-weight: bold; cursor: pointer; }
 <div id="overlay" class="overlay"> <div class="modal"> <button class="close">&times;</button> Congrats u logged in </div> </div> <button id="button">login</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM