Blogger Information
Blog 19
fans 0
comment 0
visits 5710
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
相对定位、绝对定位与固定定位的位置偏移演示
vbokok
Original
307 people have browsed it
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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. </head>
  9. <body>
  10. <ul>
  11. <li class="one">item1</li>
  12. <li class="two">item2</li>
  13. </ul>
  14. <div class="box">box</div>
  15. </body>
  16. </html>
  17. <style>
  18. * {
  19. margin: 0;
  20. padding: 0;
  21. box-sizing: border-box;
  22. }
  23. body {
  24. border: 5px solid red;
  25. height: 20em;
  26. }
  27. ul {
  28. border: 5px solid blue;
  29. height: 14em;
  30. width: 20em;
  31. }
  32. ul li {
  33. border: 1px solid black;
  34. list-style: none;
  35. }
  36. ul li:first-child {
  37. background-color: yellow;
  38. }
  39. ul li:first-child + * {
  40. background-color: violet;
  41. }
  42. ul li.one {
  43. position: relative;
  44. top: 10px;
  45. left: 20px;
  46. }
  47. ul li.two {
  48. position: absolute;
  49. height: 200px;
  50. width: 200px;
  51. left: 0;
  52. right: 0;
  53. top: 0;
  54. bottom: 0;
  55. margin: auto auto;
  56. }
  57. .box {
  58. border: 1px solid darkgreen;
  59. background-color: greenyellow;
  60. height: 150px;
  61. width: 150px;
  62. position: fixed;
  63. right: 10px;
  64. bottom: 10px;
  65. }
  66. </style>

relative:在原始位置上稍偏移位置。
absolute:在附近位置发生元素偏移。
rixed:在HTML块内偏移,不受文档限制

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:效果不错,继续加油
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post