PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

博客列表 > position定位模态框

position定位模态框

沉寂的博客
沉寂的博客 原创
2021年01月05日 11:19:25 844浏览

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>

运行结果:
模态框

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