21_定位.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. #div0{
  10. width: 800px;
  11. height: 500px;
  12. background: #ccc;
  13. /* margin:100px; */
  14. /* 定位挪走父元素 */
  15. position: relative;
  16. left:100px;
  17. top:100px;
  18. }
  19. #div1{
  20. width: 200px;
  21. height: 100px;
  22. background: #f00;
  23. float: left;
  24. }
  25. #div2{
  26. width: 200px;
  27. height: 100px;
  28. background: #00f;
  29. float: left;
  30. /* 相对定位 */
  31. /* position: relative;
  32. left:200px;
  33. top:200px; */
  34. position: absolute;
  35. left:200px;
  36. top:50px;
  37. }
  38. #div3{
  39. width: 200px;
  40. height: 100px;
  41. background: #0f0;
  42. float: left;
  43. }
  44. #div5{
  45. width: 100px;
  46. height:200px;
  47. background: green;
  48. position: fixed;
  49. right:0px;
  50. bottom: 0px;
  51. }
  52. </style>
  53. </head>
  54. <body>
  55. <!--
  56. 定位: position
  57. relative相对定位 1、相对于自己初始位置 2、定位后空间不释放
  58. absolute绝对定位 1、相对于最近已定位的祖先元素,如果没有最近已定位的祖先元素,相对于body
  59. 2、定位后空间释放
  60. fixed固定定位 1、相对于页面可视区的位置
  61. 2、定位后空间释放
  62. static 静态的 没有定位 默认值
  63. -->
  64. <div id="div0">
  65. <div id="div1"></div>
  66. <div id="div2"></div>
  67. <div id="div3"></div>
  68. </div>
  69. <div id="div5"></div>
  70. <h1>111111哈哈哈哈哈哈哈</h1>
  71. <h1>111111哈哈哈哈哈哈哈</h1>
  72. <h1>111111哈哈哈哈哈哈哈</h1>
  73. <h1>111111哈哈哈哈哈哈哈</h1>
  74. <h1>111111哈哈哈哈哈哈哈</h1>
  75. <h1>111111哈哈哈哈哈哈哈</h1>
  76. <h1>111111哈哈哈哈哈哈哈</h1>
  77. <h1>111111哈哈哈哈哈哈哈</h1>
  78. <h1>111111哈哈哈哈哈哈哈</h1>
  79. <h1>111111哈哈哈哈哈哈哈</h1>
  80. <h1>111111哈哈哈哈哈哈哈</h1>
  81. <h1>111111哈哈哈哈哈哈哈</h1>
  82. <h1>111111哈哈哈哈哈哈哈</h1>
  83. <h1>111111哈哈哈哈哈哈哈</h1>
  84. <h1>111111哈哈哈哈哈哈哈</h1>
  85. <h1>111111哈哈哈哈哈哈哈</h1>
  86. <h1>111111哈哈哈哈哈哈哈</h1>
  87. <h1>111111哈哈哈哈哈哈哈</h1>
  88. <h1>111111哈哈哈哈哈哈哈</h1>
  89. <h1>111111哈哈哈哈哈哈哈</h1>
  90. <h1>111111哈哈哈哈哈哈哈</h1>
  91. <h1>111111哈哈哈哈哈哈哈</h1>
  92. <h1>111111哈哈哈哈哈哈哈</h1>
  93. <h1>111111哈哈哈哈哈哈哈</h1>
  94. <h1>111111哈哈哈哈哈哈哈</h1>
  95. <h1>111111哈哈哈哈哈哈哈</h1>
  96. <h1>111111哈哈哈哈哈哈哈</h1>
  97. <h1>111111哈哈哈哈哈哈哈</h1>
  98. <h1>222222222222222222</h1>
  99. <h1>111111哈哈哈哈哈哈哈</h1>
  100. </body>
  101. </html>