Css兄弟绝对定位

编程入门 行业动态 更新时间:2024-10-26 14:34:57
本文介绍了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兄弟绝对定位

本文发布于:2023-10-08 02:28:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471249.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:兄弟   Css

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!