子元素absolute定位时父元素有无relative的区别

来源:互联网 发布:linux telnet服务 编辑:程序博客网 时间:2024/06/17 23:03
  1. Html
<div id="father">    <div class="son"></div></div>

2.Css–父元素没有relative

.son{            width: 50px;            height: 50px;            background-color: yellow;            position: absolute;            top: 10px;            left: 10px;        }

这里写图片描述
3.Css–父元素有relative

.father{            width: 200px;            height: 200px;            background-color: red;            margin:0 auto;            /*position: relative;*/        }        .son{            width: 50px;            height: 50px;            background-color: yellow;            position: absolute;            top: 10px;            left: 10px;        }

这里写图片描述

阅读全文
0 0
原创粉丝点击