Css兄弟绝对定位 [英] Css Sibling Absolute Positioning

查看:957
本文介绍了Css兄弟绝对定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法绝对定位一个div相对他的兄弟姐妹?例如:在div内有两个其他div - div1和div2。我想绝对地将div2相对于div1。

解决方案

绝对定位取决于当前定位上下文,其可以包括父元素(如果绝对地或相对地定位),但将永远不包括兄弟元素。 p>

你可以重组你的dom,这样你有一个父子而不是兄弟姐妹?如果是这样,您可以将父级的位置设置为relative或绝对,将该子级的位置设置为absolute,并且该子级的位置将相对于父级为绝对位置。


Is there any way to absolutely position a div relatively to his sibling? For example: Inside a div there are two other divs - div1 and div2. I want to absolutely position div2 relatively to div1.

解决方案

Absolute positioning is dependent on the "current positioning context", which may include a parent element (if absolutely or relatively positioned) but will never include a sibling element.

Can you reorganize your dom so that you have a parent-child instead of siblings? If so, you could set the parent's position to relative or absolute and the child's position to absolute and the child's position would remain absolute in relation to the parent.

这篇关于Css兄弟绝对定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆