Blogger Information
Blog 7
fans 0
comment 0
visits 2766
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
绝对定位与固定定位的理解
风残念北的博客
Original
307 people have browsed it

1.绝对定位

代码演示

  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>Document</title>
  8. </head>
  9. <body>
  10. <ul>
  11. <li>item1</li>
  12. <li class="absolute">item2</li>
  13. </ul>
  14. <style>
  15. * {
  16. margin: 0;
  17. padding: 0;
  18. box-sizing: border-box;
  19. }
  20. body {
  21. border: 3px solid red;
  22. }
  23. ul {
  24. border: 3px solid blue;
  25. width: 400px;
  26. height: 400px;
  27. }
  28. ul li{
  29. height: 30px;
  30. border: 1px solid black;
  31. list-style: none;
  32. }
  33. ul li:first-child {
  34. background-color: yellow;
  35. }
  36. ul li:first-child + * {
  37. background-color: green;
  38. }
  39. ul li.absolute {
  40. position: absolute;
  41. top: 200px;
  42. left: 300px;
  43. }
  44. </style>
  45. </body>
  46. </html>

效果演示

2.固定定位

代码演示

  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>Document</title>
  8. </head>
  9. <body>
  10. <div class="box">广告位</div>
  11. <style>
  12. body {
  13. min-height: 2000px;
  14. }
  15. .box {
  16. background-color: green;
  17. height: 100px;
  18. width: 150px;
  19. position: fixed;
  20. bottom: 10px;
  21. right: 5px;
  22. }
  23. </style>
  24. </body>
  25. </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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!