13.定位.html 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #box {
  9. width: 500px;
  10. height: 1600px;
  11. border: 1px solid #000;
  12. margin: 0 auto;
  13. /* position: relative; */
  14. }
  15. #box div {
  16. width: 200px;
  17. height: 200px;
  18. margin-top: 15px;
  19. }
  20. .box1 {
  21. background: firebrick;
  22. }
  23. .box2 {
  24. background: blue;
  25. /* position: sticky;
  26. top: 20px; */
  27. /* position: static; */
  28. position: fixed;
  29. /* position: relative; */
  30. /* position: absolute; */
  31. top: 100px;
  32. left: 100px;
  33. }
  34. .box3 {
  35. background: plum;
  36. }
  37. .box4 {
  38. background: yellow;
  39. }
  40. .box5 {
  41. background: aqua;
  42. }
  43. .box6 {
  44. background: pink;
  45. }
  46. .box7 {
  47. background: purple;
  48. }
  49. </style>
  50. </head>
  51. <body>
  52. <!--
  53. 一个网页构成:
  54. 文档流 浮动 定位
  55. position:
  56. 方向:top bottom right left
  57. 1.sticky 粘性定位 常用于吸顶效果 搭配top使用
  58. 2.static 静态定位 对页面不产生任何效果
  59. 3.fixed 固定定位 相对于可视窗口定位 脱离文档流 不占位
  60. 子绝父相
  61. 4.relative 相对定位 相对于自身定于 不脱离文档流 占位
  62. 5.absolute
  63. a.父级未开启定位 自己本身定位 相对于可视窗口定位 脱离文档流 不占位
  64. b.父级开启定位 relative 子集相对于父级进行定位 脱离文档流 不占位
  65. -->
  66. <div id="box">
  67. <div class="box1"></div>
  68. <div class="box2"></div>
  69. <div class="box3"></div>
  70. <div class="box4"></div>
  71. <div class="box5"></div>
  72. <div class="box6"></div>
  73. <div class="box7"></div>
  74. </div>
  75. </body>
  76. </html>