问题描述
有没有办法绝对定位一个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兄弟绝对定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!