Blogger Information
Blog 7
fans 0
comment 0
visits 3447
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
实例演示:模态框
Original
572 people have browsed it

代码

html

  1. <body>
  2. <header>
  3. <h1 class="title">千千的博客</h1>
  4. <button onclick="showModal()">登录</button>
  5. </header>
  6. <!-- 模态框 -->
  7. <div class="modal">
  8. <!-- 1.半透明的遮罩 -->
  9. <div class="modal-bg" onclick="closeModal()"></div>
  10. <form action="" class="modal-form">
  11. <fieldset style="display: grid; gap: 1em">
  12. <legend>用户登录</legend>
  13. <input type="email" name="email" placeholder="user@email.com" />
  14. <input type="password" name="password" placeholder="不少于6位" />
  15. <button>登录</button>
  16. </fieldset>
  17. </form>
  18. </div>
  19. <script src="modal.js"></script>
  20. </body>

css样式

<link rel="stylesheet" href="modaltext.css">

  1. /* 初始化 */
  2. *{
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. /* 头部 */
  8. header{
  9. background-color: coral;
  10. padding: 2em 5em;
  11. display: flex;
  12. }
  13. /* logo */
  14. header .title{
  15. font-weight:lighter;
  16. font-style:italic;
  17. color:grey;
  18. letter-spacing:50px;
  19. text-shadow: 1px 1px 1px white
  20. }
  21. /* 登录按钮 */
  22. header button{
  23. margin-left: auto;
  24. margin-top: auto;
  25. width: 6em;
  26. height: 2em;
  27. border: none;
  28. border-radius:0.5em;
  29. }
  30. header button:hover{
  31. cursor: pointer;
  32. background-color: coral;
  33. color: white;
  34. box-shadow: 0 0 10px #fff;
  35. transition: 0.5s;
  36. }
  37. /* 模态框 */
  38. .modal .modal-form fieldset {
  39. height:15.5em;
  40. background-color: lightsalmon;
  41. border: none;
  42. padding: 2em 3em;
  43. box-shadow:0 0 10px #888;
  44. }
  45. /* 模态框表单标题 */
  46. .modal .modal-form fieldset legend {
  47. padding:7px 1.5em;
  48. color: #fff;
  49. border:solid white 0.5px;
  50. background-color: orange;
  51. }
  52. .modal .modal-form fieldset input {
  53. height:3em;
  54. padding-left:1em;
  55. border: 1px solid #DDD;
  56. outling:none;
  57. font-size: 14px;
  58. }
  59. /* :focus: 表单控件,获取焦点时的样式 */
  60. .modal .modal-form fieldset input:focus {
  61. box-shadow:0 0 10px rgb(90, 90, 90);
  62. border:none;
  63. }
  64. .modal .modal-form fieldset button{
  65. background-color: orange;
  66. color:white;
  67. border:none;
  68. height:3em;
  69. font-size:16px;
  70. height:2.5em;
  71. box-shadow:0 0 10px white;
  72. }
  73. .modal .modal-form fieldset button:hover{
  74. background-color:coral;
  75. /* cursor: 网页浏览时用户鼠标指针的样式或图形形状。pointer:光标为一只手 */
  76. cursor:pointer;
  77. }
  78. /* 定位 */
  79. .modal .modal-form {
  80. position:fixed;
  81. top:10em;
  82. left:35em;
  83. right:35em;
  84. }
  85. /* 遮罩 */
  86. .modal .modal-bg {
  87. position: fixed;
  88. /* 坐标全部清零,定位到四个顶点 */
  89. top: 0;
  90. left: 0;
  91. right: 0;
  92. bottom: 0;
  93. background-color: rgb(0,0,0,0.5);
  94. }
  95. .modal{
  96. display:none;
  97. }

效果


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