Blogger Information
Blog 64
fans 2
comment 1
visits 46830
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
定位的类型与应用场景和使用条件、模态框的应用
Y的博客
Original
700 people have browsed it

定位的类型与应用场景和使用条件

  1. 定位的类型
  • 静态定位(position: static) 默认,也就是文档流定位,元素的显示位置与源码顺序一致;
  • 相对定位(position: relative)相对于该元素在文档流中的原始位置进行偏移;

    1. <style>
    2. * {
    3. padding: 0;
    4. margin: 0;
    5. box-sizing: border-box;
    6. }
    7. .box {
    8. height: 10em;
    9. width: 10em;
    10. background-color: seagreen;
    11. }
    12. .box h2 {
    13. width: 4em;
    14. height: 1.5em;
    15. background-color: skyblue;
    16. position: relative;
    17. top: .1em;
    18. left:.1em;
    19. }
  • 绝对定位 (position: absolue) 相对于它的祖先中离它最近的”定位元素”的位置发生偏移

    1. <style>
    2. * {
    3. padding: 0;
    4. margin: 0;
    5. box-sizing: border-box;
    6. }
    7. .box {
    8. height: 10em;
    9. width: 10em;
    10. background-color: seagreen;
    11. position: relative;
    12. top: 3em;
    13. left: 4em;
    14. }
    15. .box h2 {
    16. width: 4em;
    17. height: 1.5em;
    18. background-color: skyblue;
    19. position: absolute;
    20. top: 5em;
    21. left: 5em;
    22. }
    23. </style>
  • 固定定位(position: fixed)是绝对定位的一个特例,它始终相对于html定位

    1. <style>
    2. * {
    3. padding: 0;
    4. margin: 0;
    5. box-sizing: border-box;
    6. }
    7. .box {
    8. height: 10em;
    9. width: 10em;
    10. background-color: seagreen;
    11. position: fixed;
    12. right: 1em;
    13. bottom: 1em;
    14. }
    15. .box h2 {
    16. width: 4em;
    17. height: 1.5em;
    18. background-color: skyblue;
    19. position: relative;
    20. top: .1em;
    21. left: .1em;
    22. }
    23. </style>

    2.模态框的应用


  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>模态框</title>
  7. <style>
  8. * {
  9. padding: 0;
  10. margin: 0;
  11. box-sizing: border-box;
  12. }
  13. header {
  14. background-color: lightgrey;
  15. padding: 0.5em 2em;
  16. overflow: hidden;
  17. }
  18. header h2 {
  19. float: left;
  20. }
  21. header button {
  22. float: right;
  23. width: 10em;
  24. height: 2.5em;
  25. border-radius: 0.2em;
  26. }
  27. header button:hover {
  28. cursor: pointer;
  29. background-color: lightseagreen;
  30. }
  31. .modal .modal-backdrop {
  32. background-color: rgb(0, 0, 0, 0.5);
  33. position: fixed;
  34. top: 0;
  35. left: 0;
  36. right: 0;
  37. bottom: 0;
  38. }
  39. .modal .modal-body {
  40. padding: 1em;
  41. min-width: 20em;
  42. border: 1px solid #000;
  43. background-color: rgba(176, 235, 225, 0.781);
  44. position: fixed;
  45. top: 5em;
  46. left: 30em;
  47. right: 30em;
  48. }
  49. .modal .modal-body .close {
  50. float: right;
  51. }
  52. .modal .modal-body table {
  53. margin: auto;
  54. padding: 1em;
  55. }
  56. .modal form table button {
  57. width: 6em;
  58. height: 3em;
  59. background-color: thistle;
  60. position: relative;
  61. top: 1em;
  62. left: 8em;
  63. }
  64. .modal form table button:hover {
  65. cursor: pointer;
  66. background-color: turquoise;
  67. }
  68. .modal {
  69. display: none;
  70. }
  71. </style>
  72. </head>
  73. <body>
  74. <!-- 页眉 -->
  75. <header>
  76. <h2>我的博客</h2>
  77. <button>登录</button>
  78. </header>
  79. <!-- 模态框 -->
  80. <div class="modal">
  81. <!-- 蒙版:用来遮罩后面的内容使他半透明 -->
  82. <div class="modal-backdrop"></div>
  83. <!-- 主体 -->
  84. <div class="modal-body">
  85. <button class="close">关闭</button>
  86. <form action="" method="post">
  87. <table>
  88. <caption>用户登录</caption>
  89. <tr>
  90. <td><label for="email">邮箱</label></td>
  91. <td><input type="email"></td>
  92. </tr>
  93. <tr>
  94. <td><label for="password">密码</label></td>
  95. <td><input type="password" name="password" id="password"></td>
  96. </tr>
  97. <tr>
  98. <td><button>登录</button></td>
  99. </tr>
  100. </table>
  101. </form>
  102. </div>
  103. </div>
  104. <script src="../1221/modal.js"></script>
  105. </body>
  106. </html>
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!