02.固定定位.html 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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>固定定位</title>
  8. <style>
  9. /*
  10. 固定定位
  11. -将元素的position属性设置为fixed则开启了元素的固定定位
  12. -固定定位也是一种绝对定位,所以固定定位的大部分特点都和绝对定位一样
  13. 唯一不同的是,固定定位永远参照于浏览器的视口进行定位
  14. 固定定位的元素不会随网页的滚动条滚动
  15. */
  16. body{
  17. font-size: 50px;
  18. }
  19. .box1{
  20. width: 200px;
  21. height: 200px;
  22. background-color: #bfa;
  23. }
  24. .box2{
  25. width: 200px;
  26. height: 200px;
  27. background-color:orange;
  28. }
  29. .box3{
  30. width: 200px;
  31. height: 200px;
  32. background-color: yellow;
  33. }
  34. .box4{
  35. width: 400px;
  36. height: 400px;
  37. background-color: tomato;
  38. }
  39. .box5{
  40. width: 300px;
  41. height: 300px;
  42. background-color: aliceblue;
  43. }
  44. </style>
  45. </head>
  46. <body>
  47. <div class="box1">1</div>
  48. <div class="box4">
  49. 4
  50. <div class="box5">
  51. 5
  52. <div class="box2">2</div>
  53. </div>
  54. </div>
  55. <div class="box3">3</div>
  56. </body>
  57. </html>