定位.html 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 div {
  9. width: 200px;
  10. height: 200px;
  11. margin-top:15px;
  12. font-size: 30px;
  13. text-align: center;
  14. line-height: 200px;
  15. border:1px solid #000;
  16. }
  17. .three {
  18. /* position: sticky; */
  19. /* position: static;
  20. top: 40px; */
  21. background-color: #f00;
  22. }
  23. .four {
  24. position: fixed;
  25. bottom: 100px;
  26. left:100px;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <!--
  32. 为什么会引出定位
  33. 一个网页:
  34. 文档流
  35. 浮动
  36. 定位
  37. position:定位 top left right bottom
  38. 1.sticky 粘性定位 吸顶效果 top 一起使用 不脱离文档流 占位
  39. 2.static 静态定位 不对页面产生影响
  40. 3.fixed 固定定位 脱离文档流 不占位 相对于祖先元素定位
  41. -->
  42. <div class="box">
  43. <div class="one">1</div>
  44. <div class="two">2</div>
  45. <div class="three">3</div>
  46. <div class="four">4</div>
  47. <div class="five">5</div>
  48. <div class="six">6</div>
  49. <div class="seven">7</div>
  50. <div class="ejght">8</div>
  51. </div>
  52. </body>
  53. </html>