是否可以将元素放置在相对于文档绝对位置的相对放置的容器中?
以下代码:
<div id="container1" style="position: relative">
<div id="container2" style="position: absolute; top: 5px; left: 5px">
I will be positioned inside my parent!!
</div>
<div id="container3" style="position: absolute;">
I would like to be positioned relative to the document. But how?
</div>
</div>
我知道将
container3
移出container1
是一种解决方案,但是让我们假设这是不可能的,因为我无法控制模板,只能控制CSS。
最佳答案
没有伴侣,对不起,您不能。如果您知道div距顶部有多远,则可以使用负值将其推向您的位置,但它始终相对于父div。
关于css - 将元素绝对定位到相对定位元素内的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6569319/