Blogger Information
Blog 18
fans 0
comment 0
visits 7745
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
模态框案例
只如初见
Original
553 people have browsed it

模态框

html代码

  1. <header>
  2. <h2 class="title">小刘博客</h2>
  3. <button onclick="showModal()">登录</button>
  4. </header>
  5. <!-- 模态框 -->
  6. <div class="modal">
  7. <!-- 1. 半透明的遮罩层 -->
  8. <div class="modal-bg" onclick="closeModal()"></div>
  9. <!-- 2. 弹层表单 -->
  10. <form action="" class="modal-form">
  11. <fieldset style="display: grid; gap: 1em">
  12. <legend>用户登录</legend>
  13. <input type="text" name="username" placeholder="请输入用户名" />
  14. <input type="password" name="password" placeholder="不少于6位" />
  15. <input type="email" name="email" placeholder="user@email.com" />
  16. <button>登录</button>
  17. </fieldset>
  18. </form>
  19. </div>

css代码

  1. /* 初始化 */
  2. * {
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. /* 清除所有元素的外边距和内边距
  7. 将盒子大小计算方式改为到盒子边框(不用考虑间距、边框等问题的影响) */
  8. }
  9. /* 头部 */
  10. header {
  11. background-color: #0d63fe;
  12. padding: 1em 2em;
  13. display: flex;
  14. }
  15. /* logo */
  16. header .title {
  17. font-weight: lighter;
  18. color: white;
  19. /* 文字间距 */
  20. letter-spacing: 2px;
  21. /* 阴影 */
  22. text-shadow: 1px 1px 3px #555;
  23. }
  24. /* 登录按钮 */
  25. header button {
  26. margin-left: auto;
  27. width: 5em;
  28. border: none;
  29. /* 圆角 */
  30. border-radius: 0.3em;
  31. }
  32. header button:hover {
  33. cursor: pointer;
  34. background-color: brown;
  35. color: #fff;
  36. box-shadow: 0 0 5px #fff;
  37. /* 过度时间 */
  38. transition: 0.3s;
  39. }
  40. /* 模态框 */
  41. .modal .modal-form fieldset {
  42. height: auto;
  43. background-color: #fcfcfc;
  44. border: none;
  45. padding: 1em 3em 3em;
  46. box-shadow: 0 0 5px #888;
  47. }
  48. /* 模态框表单标题 */
  49. .modal .modal-form fieldset legend {
  50. padding: 7px 1.5em;
  51. background-color: #0d63fe;
  52. color: white;
  53. text-align: center;
  54. margin: 0 auto;
  55. }
  56. .modal .modal-form fieldset input {
  57. height: 3em;
  58. padding-left: 1em;
  59. outline: none;
  60. border: 1px solid #ddd;
  61. font-size: 14px;
  62. }
  63. /* :focus: 表单控件,获取焦点时的样式 */
  64. .modal .modal-form fieldset input:focus {
  65. box-shadow: 0 0 8px #888;
  66. border: none;
  67. }
  68. .modal .modal-form fieldset button {
  69. background-color: #0d63fe;
  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. }
  80. /* 定位 */
  81. .modal .modal-form {
  82. position: fixed;
  83. width: 300px;
  84. top: 10em;
  85. /* 任何时候都居中 */
  86. left: 50%;
  87. margin-left: -150px;
  88. }
  89. /* 遮罩 */
  90. .modal .modal-bg {
  91. position: fixed;
  92. /* 坐标全部清0,请定位到四个顶点 */
  93. top: 0;
  94. left: 0;
  95. right: 0;
  96. bottom: 0;
  97. background-color: rgb(0, 0, 0, 0.5);
  98. }
  99. .modal {
  100. display: none;
  101. }

效果图

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!