Blogger Information
Blog 18
fans 0
comment 0
visits 16006
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
position定位模态框
沉寂的博客
Original
877 people have browsed it

position定位模态框

position定位可以分为

1.静态定位static系统默认的文档流定位方式;
2.relative 相对定位,相对于本身位置的偏移;
3.absolute 绝对定位,相对于离自己最近的定位元素(position值为relative absolute值)进行偏移;
4.fixed 固定定位,相对于根元素进行偏移,一般用于广告。
position模态框代码如下:

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. /* 页眉 */
  7. header {
  8. background-color: #ccc;
  9. padding: 0.5em 2em;
  10. overflow: hidden;
  11. }
  12. header h2 {
  13. float: left;
  14. }
  15. header button {
  16. float: right;
  17. width: 10em;
  18. height: 2.5em;
  19. }
  20. header button:hover {
  21. cursor: pointer;
  22. background-color: #fff;
  23. }
  24. /* 模态框 */
  25. /* 蒙板 */
  26. .modal .modal-backdrop {
  27. background-color: rgb(0, 0, 0, 0.5);
  28. position: fixed;
  29. top: 0;
  30. left: 0;
  31. right: 0;
  32. bottom: 0;
  33. }
  34. .modal .modal-body {
  35. padding: 1em;
  36. min-width: 20em;
  37. border: 1px solid #000;
  38. background: linear-gradient(to right, lightcyan, #fff);
  39. /* 固定定位 */
  40. position: fixed;
  41. top: 5em;
  42. left: 30em;
  43. right: 30em;
  44. }
  45. .modal form table {
  46. width: 80%;
  47. }
  48. .modal form table caption {
  49. font-weight: bold;
  50. margin-bottom: 1em;
  51. }
  52. .modal form table td {
  53. padding: 0.5em;
  54. }
  55. .modal form table td:first-of-type {
  56. width: 5em;
  57. }
  58. .modal form table input {
  59. position: absolute;
  60. left: 8em;
  61. width: 20em;
  62. height: 2em;
  63. }
  64. .modal form table button {
  65. position: absolute;
  66. left: 8em;
  67. /* bottom: 0.5em; */
  68. width: 20em;
  69. height: 2em;
  70. }
  71. /* 定位父级 */
  72. .modal-body {
  73. position: relative;
  74. }
  75. .modal .close {
  76. position: absolute;
  77. width: 4em;
  78. height: 2em;
  79. top: 1em;
  80. right: 1em;
  81. }
  82. .modal .close:hover {
  83. cursor: pointer;
  84. background-color: red;
  85. color: white;
  86. }
  87. /* 页面初始化时,模态框应该隐藏 */
  88. .modal {
  89. display: none;
  90. }

html结构代码如下:

  1. <header>
  2. <h2>我的博客</h2>
  3. <button>登录</button>
  4. </header>
  5. <!-- 模态框 -->
  6. <div class="modal">
  7. <div class="modal-backdrop"></div>
  8. <!-- 主体 -->
  9. <div class="modal-body">
  10. <button class="close">关闭</button>
  11. <form action="#" method="POST">
  12. <table>
  13. <caption>
  14. 用户登录
  15. </caption>
  16. <tr>
  17. <td><label for="email">邮箱:</label></td>
  18. <td><input type="email" name="email" id="email" /></td>
  19. </tr>
  20. <tr>
  21. <td><label for="password">密码:</label></td>
  22. <td><input type="password" name="password" id="password" /></td>
  23. </tr>
  24. <tr>
  25. <td><button>登录</button></td>
  26. </tr>
  27. </table>
  28. </form>
  29. </div>
  30. </div>
  31. <script src="../JavaScript/modal.js"></script>

运行结果:
模态框

Correcting teacher:天蓬老师天蓬老师

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