定位.html 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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: 400px;
  10. height: auto;
  11. border: 4px solid #f00;
  12. margin-left: 300px;
  13. /* position: relative; */
  14. }
  15. .box div {
  16. width: 200px;
  17. height: 200px;
  18. margin-top:15px;
  19. font-size: 30px;
  20. text-align: center;
  21. line-height: 200px;
  22. border:1px solid #000;
  23. }
  24. .three {
  25. /* position: sticky; */
  26. /* position: static;
  27. top: 40px; */
  28. background-color: #f00;
  29. }
  30. .four {
  31. position: fixed;
  32. bottom: 100px;
  33. left:100px;
  34. background: orange;
  35. /* position: relative;
  36. top: 100px;
  37. left: 300px; */
  38. /* position: absolute;
  39. top: 300px;
  40. left: 20px; */
  41. }
  42. </style>
  43. </head>
  44. <body>
  45. <!--
  46. 为什么会引出定位
  47. 一个网页:
  48. 文档流
  49. 浮动
  50. 定位
  51. position:定位 top left right bottom
  52. 1.sticky 粘性定位 吸顶效果 top 一起使用 不脱离文档流 占位
  53. 2.static 静态定位 不对页面产生影响
  54. 3.fixed 固定定位 脱离文档流 不占位 相对于祖先元素定位
  55. 4.relative 相对定位 不脱离文档流 占位 相对于自己本身去定位
  56. 5.absolute 绝对定位 脱离文档流 不占位
  57. a.相对于祖先元素进行定位 当父级没有定位时
  58. b.父级存在定位 (相对定位) absolute就是相对于父级进行定位
  59. -->
  60. <div class="box">
  61. <div class="one">1</div>
  62. <div class="two">2</div>
  63. <div class="three">3</div>
  64. <div class="four">4</div>
  65. <div class="five">5</div>
  66. <div class="six">6</div>
  67. <div class="seven">7</div>
  68. <div class="ejght">8</div>
  69. </div>
  70. </body>
  71. </html>