06-positon.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. .innerDiv{
  9. width: 100px;
  10. height: 100px;
  11. }
  12. .d1{
  13. background-color: rgb(235, 159, 159);
  14. /* position: static; */
  15. /* top left right bottom */
  16. /* position: absolute;
  17. left: 300px;
  18. top: 100px; */
  19. /* position: relative;
  20. left: 30px;
  21. top: 30px; */
  22. position: fixed;
  23. right: 30px;
  24. top: 30px;
  25. }
  26. .d2{
  27. background-color: rgb(231, 146, 44);
  28. }
  29. .d3{
  30. background-color: rgb(180, 180, 235);
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <!-- css定位 -->
  36. <!-- 不设置定位的值时 是静态定位 static -->
  37. <!-- 静态定位 就是没有定位 元素出现在该出现的位置 块级元素垂直排列 行内元素水平排列-->
  38. <!-- 绝对定位 absolute 元素在页面上固定位置 此时会让出原来的位置 其他元素可以占用-->
  39. <!-- 相对定位 relative 相对于原来的位置定位 定位后保留原来位置 其他元素不占用 -->
  40. <!-- 固定定位 fixed 不会随着页面的上下移动而移动。此时会让出原来的位置 -->
  41. <div class="innerDiv d1">框1</div>
  42. <div class="innerDiv d2">框2</div>
  43. <div class="innerDiv d3">框3</div>
  44. </body>
  45. </html>