index.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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>Document</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. }
  12. div {
  13. width: 200px;
  14. height: 200px;
  15. margin-top: 20px;
  16. }
  17. .main {
  18. width: 400px;
  19. height: auto;
  20. border: 1px solid #000;
  21. margin-top: 0;
  22. margin: 0 auto;
  23. position: relative;
  24. }
  25. .one {
  26. background: #00f;
  27. }
  28. .two {
  29. /* position: relative;
  30. top: 100px;
  31. left: 200px; */
  32. background: #f0f;
  33. /* position: sticky;
  34. top: 40px; */
  35. }
  36. .three {
  37. background: #0ff;
  38. /* position: fixed; */
  39. /* position: static; */
  40. /* top: 100px; */
  41. /* left: 100px; */
  42. }
  43. .four {
  44. background: #f00;
  45. position: absolute;
  46. top: 100px;
  47. left: 100px;
  48. }
  49. .five {
  50. background: #ff0;
  51. }
  52. .six {
  53. background: hotpink;
  54. }
  55. .seven {
  56. background: purple;
  57. }
  58. </style>
  59. </head>
  60. <body>
  61. <!--
  62. 一个网页的组成:
  63. 标准流(文档流)
  64. 浮动
  65. 定位
  66. 定位
  67. position:
  68. 1.sticky 粘性定位 常用于吸顶效果 配合top使用 脱离文档流不占位
  69. 2.fixed 固定定位 脱离文档流不占位 相对于祖先元素定位
  70. 3.relative 相对定位 不脱离文档流占位 相对于自己本身定位
  71. 4.absolute 绝对定位
  72. a.父级盒子未定位 相对于祖先元素进行定位 脱离文档流 不占位
  73. b.父级盒子定位(相对定位) 脱离文档流 不占位 相对于父级盒子
  74. top bottom left right
  75. 5.static 静态定位 不对页面产生影响
  76. -->
  77. <div class="main">
  78. <div class="one"></div>
  79. <div class="two"></div>
  80. <div class="three"></div>
  81. <div class="four"></div>
  82. <div class="five"></div>
  83. <div class="six"></div>
  84. <div class="seven"></div>
  85. </div>
  86. </body>
  87. </html>