博主信息
博文 19
粉丝 0
评论 0
访问量 11623
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
相对定位、绝对定位与固定定位的位置偏移演示
vbokok
原创
541人浏览过
  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块内偏移,不受文档限制

批改老师:PHPzPHPz

批改状态:合格

老师批语:效果不错,继续加油
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学