Blogger Information
Blog 17
fans 0
comment 0
visits 8265
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
模态框的练习
想做一个躺平的程序员
Original
322 people have browsed it

模态框演示

代码部分

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>模态框的实现</title>
  7. <style>
  8. body{
  9. height: 2000px;
  10. }
  11. .header{
  12. /* 布局设置为弹性布局 设置背景颜色*/
  13. background-color: teal;
  14. display: flex;
  15. }
  16. .header .header-title{
  17. /*字体颜色为白色 字体加粗 选定的字体*/
  18. color: azure;
  19. font-weight: bold;
  20. font-family: serif;
  21. }
  22. /* 登录 */
  23. .header .header-login{
  24. /*左外边框自动 边框的半径1em 外边框上下为auto 宽和高为合适*/
  25. margin-left: auto;
  26. border-radius: .8em;
  27. border: none;
  28. margin-top: auto;
  29. margin-bottom: auto;
  30. width: 66px;
  31. height: 35px;
  32. }
  33. /* 登录按钮选中的状态 */
  34. .header>.header-login:hover{
  35. background-color: darkturquoise;
  36. /* box-shadow: 右边 下边 阴影的尺寸 颜色 */
  37. box-shadow: 1px 1px 10px darkcyan;
  38. }
  39. .model .model-form .model-form-fieldset{
  40. width: 15em;
  41. background-color:rgba(63, 222, 243, 0.8);
  42. border-radius: .4em;
  43. }
  44. .model .model-form .model-form-fieldset legend{
  45. background-color: aliceblue;
  46. color:skyblue;
  47. }
  48. .model .model-form .model-form-fieldset>input{
  49. height: 2.5em;
  50. }
  51. /* 表单控件获取焦点的时候 */
  52. .model .model-form .model-form-fieldset>input:focus {
  53. box-shadow: 1em 1em 5em rgb(39, 163, 111);
  54. }
  55. .model .model-form .model-form-fieldset>button{
  56. /* 宽度为5em 高度为2em 边框半径为.3em 左外边距为6em
  57. 背景颜色为 aqua 字体加粗程度为600 字体类型 Arial, Helvetica, sans-serif;*/
  58. width: 5em;
  59. height: 2em;
  60. border-radius: .3em;
  61. margin-left: 6em;
  62. background-color: aqua;
  63. font-weight: 600;
  64. font-family: Arial, Helvetica, sans-serif;
  65. }
  66. /* 弹出登录表单时的遮罩 */
  67. .model >.model-bg{
  68. /* 固定定位 定位到视图中的四个点
  69. 背景颜色设置为 rgba模式 0.6透明状态
  70. */
  71. position: fixed;
  72. top: 0;
  73. left: 0;
  74. right: 0;
  75. bottom: 0;
  76. background-color: rgba(0, 0, 0, 0.6);
  77. }
  78. /* 表单定位 */
  79. .model .model-form {
  80. /*固定定位 距离头部的距离为15em ,左边距离为41em*/
  81. position: fixed;
  82. top:15em;
  83. left: 37em;
  84. }
  85. .model{
  86. display: none;
  87. }
  88. </style>
  89. </head>
  90. <body>
  91. <div>
  92. <div>
  93. <header class="header">
  94. <h2 class="header-title">想做一个躺平的程序员</h2>
  95. <button class="header-login" onclick="showModel()">登陆</button>
  96. </header>
  97. </div>
  98. <!-- 模态框 -->
  99. <div class="model">
  100. <!-- 半遮罩 -->
  101. <div class="model-bg" onclick="closeModel()"></div>
  102. <!-- 弹层表单 -->
  103. <form class="model-form" action="xxx" method="POST">
  104. <fieldset class="model-form-fieldset" style="display: grid;" >
  105. <legend>用户登录</legend>
  106. <label for="username">用户名:</label>
  107. <input type="text" name="username" id="username" placeholder="输入的用户名不少于两位" required>
  108. <br>
  109. <label for="psw">密码:</label>
  110. <input type="password" id="psw" name="psw" placeholder="输入的密码不少于16位" required >
  111. <br>
  112. <button type="submit">登录</button>
  113. </fieldset>
  114. </form>
  115. </div>
  116. </div>
  117. </body>
  118. <script>
  119. function showModel(){
  120. // 获取模态框的元素
  121. var model =document.querySelector(".model");
  122. //显示模态框
  123. model.style.display="block";
  124. }
  125. function closeModel(){
  126. //获取模态框的元素
  127. var model=document.querySelector(".model");
  128. // 关闭模态框
  129. model.style.display='none';
  130. }
  131. </script>
  132. </html>

页面效果如下:

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