我是新来的,我想知道如何同时将 div 的位置指定为绝对位置和相对位置,因为 div 可以同时是子级和父级。
感谢您的帮助
如果孩子处于绝对位置,任何孙子可以再次绝对定位关系中给孩子。
也就是说,孩子不需要position:relative
为孙子提供绝对定位关系中 to it.
所以孩子可能是经过考虑的具有position:absolute
因为它有自己的定位,但也是“相对的”形成参考点为了孙子的定位。
<div class="parent">
<div class="child">
<div class="g-child"></div>
</div>
</div>
.parent {
width: 350px;
height: 350px;
background: rebeccapurple;
margin: 1em auto;
position: relative;
}
.child {
position: absolute;
width: 50px;
height: 50px;
right: 50px;
top: 50px;
background: orange;
}
.g-child {
position: absolute;
width: 25px;
height: 25px;
background: #f00;
top:125%;
right: 0;
}
Codepen 演示 http://codepen.io/Paulie-D/pen/ZpZNpV
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)