有没有办法绝对将内部div放在页面顶部忽略父母的相对位置?
有没有办法绝对将内部div放在页面顶部忽略父母的相对位置?
不,除非你在DOM中重新找到它。
(运用 position:fixed
如果您希望它与窗口相关而不是与文档相关,则可能是另一种选择)
您可以使用 position: absolute;
和负值:
HTML:
<div id="parent">
<div id="child">
The child's content
</div>
</div>
CSS:
#parent
{
position: relative;
top: 200px;
border: 1px dashed #f00;
height: 50px;
width: 200px;
}
#child
{
position: absolute;
top: -200px;
}
这应该做到这一点。 你在这里的例子。
不,除非你在DOM中重新找到它。
(运用 position:fixed
如果您希望它与窗口相关而不是与文档相关,则可能是另一种选择)
您可以使用 position: absolute;
和负值:
HTML:
<div id="parent">
<div id="child">
The child's content
</div>
</div>
CSS:
#parent
{
position: relative;
top: 200px;
border: 1px dashed #f00;
height: 50px;
width: 200px;
}
#child
{
position: absolute;
top: -200px;
}
这应该做到这一点。 你在这里的例子。