博客列表 >模态框案例

模态框案例

Blackeye
Blackeye原创
2022年03月27日 13:21:54429浏览
  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>Dave Blog</title>
  8. <link rel="stylesheet" href="hw.css">
  9. </head>
  10. <body>
  11. <!-- 简易的后台管理页面头部 -->
  12. <header>
  13. <div class="left">
  14. <span>Dave's Blog</span>
  15. </div>
  16. <div class="right">
  17. <span>Dave</span>
  18. <button onclick="showshadow()">登录</button>
  19. </div>
  20. </header>
  21. <!-- 模态框主体 -->
  22. <main>
  23. <div class="login">
  24. <!-- 遮罩 -->
  25. <div class="shadow" onclick="closeshadow()"></div>
  26. <!-- 登录页面 -->
  27. <form action="" class="modal-form">
  28. <fieldset style="display: grid; gap: 1em">
  29. <legend>用户登录</legend>
  30. <input type="email" name="email" placeholder="user@email.com" />
  31. <input type="password" name="password" placeholder="不少于6位" />
  32. <button>登录</button>
  33. </fieldset>
  34. </form>
  35. </div>
  36. </main>
  37. </body>
  38. <!-- 模态框显示关闭js -->
  39. <script>
  40. function showshadow(){
  41. let login = document.querySelector(".login");
  42. login.style.display = 'block';
  43. }
  44. function closeshadow(){
  45. let login = document.querySelector(".login");
  46. login.style.display = 'none';
  47. }
  48. </script>
  49. </html>
  1. *{
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. /* 修改根元素 */
  7. html{
  8. font-size: 20px;
  9. }
  10. header{
  11. width: 1fr;
  12. height: 3rem;
  13. background-color: deepskyblue;
  14. position: relative;
  15. }
  16. .left{
  17. /* 设置左边logo位置 */
  18. left: 0;
  19. margin-left: 3rem;
  20. margin-top: 0.5rem;
  21. position: absolute;
  22. /* 扩大logo */
  23. font-size: 1.5rem;
  24. font-weight: bold;
  25. color: rgb(179, 105, 179);
  26. }
  27. .right{
  28. /* 确定右边控件定位 */
  29. right: 0;
  30. margin-right: 4rem;
  31. margin-top: 0.75rem;
  32. position: absolute;
  33. }
  34. .right span{
  35. /* 细节右边控件 */
  36. margin-right: 1rem;
  37. color: rgb(179, 105, 179);
  38. }
  39. .right button{
  40. /* 初始化button样式 */
  41. border:none;
  42. outline: none;
  43. width: 2rem;
  44. height: 1.5rem;
  45. border-radius: 0.5em;
  46. background-color: rgb(0,0,0,0.5);
  47. color: white;
  48. }
  49. .right button:hover{
  50. /* 为button增加选中样式 */
  51. cursor: pointer;
  52. background-color: orange;
  53. transition: background-color 0.75s;
  54. }
  55. /* 初始化遮罩 */
  56. .login .shadow{
  57. position: fixed;
  58. top: 0;
  59. right: 0;
  60. bottom: 0;
  61. left: 0;
  62. background-color: rgb(0,0,0,0.5);
  63. }
  64. /* 初始化登陆框样式 */
  65. .login form fieldset{
  66. position: fixed;
  67. width: 15rem;
  68. /* height: 11em; */
  69. margin-left: 40vw;
  70. margin-top: 40vh;
  71. background-color: deepskyblue;
  72. }
  73. /* 初始化登陆框样式细节 */
  74. .login form fieldset{
  75. border: none;
  76. border-radius: 0.5em;
  77. }
  78. /* 初始化legend样式属性 */
  79. .login form fieldset legend{
  80. background-color: rgb(6, 81, 179);
  81. color: white;
  82. margin-left: 1rem;
  83. padding: 1rem;
  84. font-size: 30px;
  85. border: none;
  86. border-radius: 0.5em;
  87. margin-bottom: 1rem;
  88. }
  89. /* 初始化input */
  90. .login form fieldset input{
  91. height: 1.5rem;
  92. width: 13rem;
  93. margin-left: 1rem;
  94. border: none;
  95. border-radius: 0.5em;
  96. }
  97. /* 设置input聚焦样式 */
  98. .login form fieldset input:focus{
  99. box-shadow: 0 0 8px #888;
  100. border: none;
  101. }
  102. /* 设置登陆框登录按钮样式 */
  103. .login form fieldset button{
  104. height: 1.25rem;
  105. width: 7.5rem;
  106. border: none;
  107. border-radius: 0.5em;
  108. background-color: rgb(0,0,0,0.5);
  109. color: white;
  110. margin-left: 3.5rem;
  111. margin-bottom: 1rem;
  112. }
  113. /* 为登录按钮添加样式 */
  114. .login form fieldset button:hover{
  115. cursor: pointer;
  116. background-color: orange;
  117. transition: background-color 0.75s;
  118. }
  119. /* 默认隐藏登陆框 */
  120. .login{
  121. display: none;
  122. }

效果

display1
display2

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议