Blogger Information
Blog 47
fans 0
comment 3
visits 44825
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
绝对定位与固定定位——模态框案例
江流
Original
1013 people have browsed it

登录是使用遮罩功能——模态框

页头部分

  • html:
    1. <header>
    2. <h2>我的博客</h2>
    3. <button onclick="document.querySelector('.modal').style.display='block'">
    4. 登录
    5. </button>
    6. </header>
  • css
    1. * {
    2. margin: 0;
    3. padding: 0;
    4. box-sizing: border-box;
    5. }
    6. body {
    7. background-color: #eee;
    8. }
    9. header {
    10. background-color: lightseagreen;
    11. padding: 0.5em 1em;
    12. display: flex;
    13. }
    14. header button {
    15. margin-left: auto;
    16. width: 4em;
    17. }

    模态框部分

  • html:
  1. <div class="modal">
  2. <!-- 半透明的遮罩 -->
  3. <div
  4. class="modal-bg"
  5. onclick="this.parentNode.style.display='none'"
  6. ></div>
  7. <form action="" class="modal-form">
  8. <fieldset>
  9. <legend>用户登录</legend>
  10. <div>
  11. <label for=""> 用户名: </label>
  12. <input type="text" />
  13. </div>
  14. <div>
  15. <label for="">密码:</label>
  16. <input type="password" />
  17. </div>
  18. <div><button>登录</button></div>
  19. </fieldset>
  20. </form>
  21. </div>
  • CSS:
  1. .modal {
  2. position: relative;
  3. }
  4. .modal .modal-form fieldset {
  5. background-color: lightcyan;
  6. border: none;
  7. padding: 2em;
  8. box-shadow: 0 0 5px #888;
  9. }
  10. .modal .modal-form fieldset legend {
  11. padding: 5px 1em;
  12. background-color: rebeccapurple;
  13. color: white;
  14. }
  15. .modal .modal-form {
  16. position: fixed;
  17. top: 10em;
  18. left: 20em;
  19. right: 20em;
  20. }
  21. .modal .modal-bg {
  22. position: fixed;
  23. top: 0;
  24. right: 0;
  25. bottom: 0;
  26. left: 0;
  27. background-color: rgb(0, 0, 0, 0.5);
  28. }
  29. .modal {
  30. display: none;
  31. }

页面加载效果:

点击登录按钮后效果:

点击模态框任意部分,取消登录,回到加载状态。

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post