登录  /  注册
博主信息
博文 10
粉丝 0
评论 0
访问量 4388
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
定位布局:绝对定位和固定定位
P粉854918706
原创
503人浏览过

定位布局:相对定位、绝对定位和固定定位

相对定位:以自身初始状态为基准进行定位,定位父级为自身,但初始状态受包含父级(非定位父级)影响

绝对定位:以最近的position属性非static的定位父级为定位基准,如一直未能找到static的定位父级,则以html为基准进行定位

固定定位:以html最初包含块或者视口为定位父级进行定位,完全不收其他因素影响

以上区别在示例代码中:right:400px能够清楚看出区别

<!DOCTYPE html><html lang="zh-CN"><head>    <meta charset="UTF-8">    <meta http-equiv="X-UA-Compatible" content="IE=edge">    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <title>定位布局:相对定位、绝对定位和固定定位</title></head><body>    <style>        .buju{            width:800px;            height:200px;            border:3px solid red;            position:relative;            margin-bottom: 10px;            margin-left:auto;            margin-right: auto;        }        .dingwei1{            width:400px;            height:100px;            border: 2px dashed green;            position:relative;            right:400px;            text-align: center;        }        .dingwei2{            width:400px;            height:100px;            border: 2px dashed yellow;            position:absolute;            right:400px;            bottom: 10px;            text-align: center;        }        .dingwei3{            width:400px;            height:100px;            border: 2px dashed blue;            position:fixed;            right: 400px;            bottom:20px;            text-align: center;        }    </style>    <div class="buju">        <div class="dingwei1">相对定位示例</div>    </div>    <div class="buju">        <div class="dingwei2">绝对定位示例</div>    </div>    <div class="buju">        <div class="dingwei3">固定定位示例</div>    </div></body></html>
批改老师:PHPzPHPz

批改状态:合格

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

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

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