有没有办法绝对定位一个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兄弟绝对定位
发布评论