3 回答
qff
TA贡献5条经验 获得超4个赞
绝对定位是相对于最近的已定位祖先元素,如果元素没有已定位的祖先元素,那么它的位置相对于最初的包含块。
设置父元素相对定位,子元素绝对定位,那么子元素就是相对于这个父元素的位置来定位的。
火狼战队
TA贡献3条经验 获得超2个赞
如果父元素用的绝对,绝对定位脱离文档流,那么父元素的临近元素会与该父元素重叠。-------来自一个后端开发学习者的前端感悟。
这里有我写的一段代码,你看下。
<style>
div {font-size: 15px;color: #fff;}
.test1{width: 400px;height: 400px;background: #234;position: relative;}
.test2 {width: 300px;height: 300px;background: #345;position: absolute;
left: 40px;top: 40px; }
.test{
width: 500px;height: 500px;background: #123;
}
</style>
</head>
<body>
<div class="test1">
test1
<div class="test2">test2</div>
</div>
<div class="test">
test
</div>
</body>你可以试一试如果把父元素改成绝对定位会出现什么情况。。。
- 3 回答
- 0 关注
- 15594 浏览
相关问题推荐
添加回答
举报
0/150
提交
取消
