Blogger Information
Blog 12
fans 0
comment 0
visits 6064
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
模态框案例实战
天空
Original
438 people have browsed it

页面效果

模态框实战

HTML代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>模态框(定位实战)</title>
  8. <link rel="stylesheet" href="modal_log.css">
  9. </head>
  10. <body>
  11. <header>
  12. <h2 class="title">天空的博客</h2>
  13. <button onclick="showModal()">登录</button>
  14. </header>
  15. <!-- 模态框 -->
  16. <!-- 先写一个盒子 -->
  17. <div class="modal">
  18. <!-- 1.半透明的遮罩 -->
  19. <div class="modal-bg" onclick="closeModal()"></div>
  20. <!-- 弹层表单 -->
  21. <form action="" class="modal-form">
  22. <fieldset style="display: grid; gap: 1em">
  23. <legend>用户登录</legend>
  24. <input type="email" name="email" placeholder="user@mail.com">
  25. <input type="password" name="password" placeholder="不少于6个字符">
  26. <button>登录</button>
  27. </fieldset>
  28. </form>
  29. </div>
  30. <script src="modal.js"></script>
  31. </body>
  32. </html>

CSS代码

  1. /* 初始化 */
  2. * {
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. /* 头部 */
  8. header {
  9. background-color: lightseagreen;
  10. padding: 0.5em 1em;
  11. display: flex;
  12. }
  13. /* 标题 */
  14. header .title {
  15. font-weight: lighter;
  16. font-style: italic;
  17. color: white;
  18. letter-spacing: 2px;
  19. text-shadow: 1px 1px 1px #555;
  20. }
  21. /* 登录按钮 */
  22. /* 按钮的基本样式 */
  23. header button {
  24. margin-left: auto;
  25. /* margin-right: auto; */
  26. width: 5em;
  27. border: none;
  28. border-radius: 0.5em;
  29. }
  30. /* 鼠标移上去的样式 */
  31. header button:hover {
  32. cursor: pointer;
  33. background-color: coral;
  34. color: #fff;
  35. /*发光效果 box-shadow: 向右 向下 模糊半径 颜色; */
  36. box-shadow: 0 0 5px #fff;
  37. /* 过度效果,0.3秒 */
  38. transition: 0.3s;
  39. }
  40. /* 模态框 */
  41. .modal .modal-form fieldset {
  42. height: 15.5em;
  43. background-color: lightcyan;
  44. border: none;
  45. padding: 2em 3em;
  46. box-shadow: 0 0 5px #888;
  47. }
  48. /* 模态框表单标题样式 */
  49. .modal .modal-form fieldset legend {
  50. padding: 7px 1.5em;
  51. background-color: lightseagreen;
  52. color: white;
  53. }
  54. /* 输入框 */
  55. .modal .modal-form fieldset input {
  56. height: 3em;
  57. padding-left: 1em;
  58. outline: none;
  59. border: 1px solid #ddd;
  60. font-size: 14px;
  61. }
  62. /* 输入框获得焦点的样式 */
  63. .modal .modal-form fieldset input:focus {
  64. box-shadow: 0 0 8px #888;
  65. border: none;
  66. }
  67. /* 登录按钮的样式 */
  68. .modal .modal-form fieldset button {
  69. background-color: lightseagreen;
  70. color: white;
  71. border: none;
  72. height: 3em;
  73. font-size: 16px;
  74. height: 2.5em;
  75. }
  76. .modal .modal-form fieldset button:hover {
  77. background-color: coral;
  78. cursor: pointer;
  79. box-shadow: 0 0 8px #888;
  80. transition: 00.3s;
  81. }
  82. /* 定位:固定定位:fixed */
  83. .modal .modal-form {
  84. position: fixed;
  85. /* 设为定位后就收缩到最左最上了 */
  86. top: 10em;
  87. left: 38em;
  88. right: 38em;
  89. }
  90. /* 遮罩 */
  91. .modal .modal-bg {
  92. position: fixed;
  93. /* 坐标全部清零,定位到四个顶点*/
  94. top: 0em;
  95. left: 0;
  96. right: 0;
  97. bottom: 0;
  98. background-color: rgb(0, 0, 0, 0.5);
  99. /* 半透明 */
  100. }
  101. .modal {
  102. display: none;
  103. }
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