DIV absolute positioning - maintain position after browser window resize

China☆狼群 提交于 2019-12-04 11:52:49

To make an element position absolutely to it's parent, the parent must be set to position:relative.

For example:

<div id="parent" style="margin:0 auto; width:500px; position:relative;">
    <div id="child" style="position:absolute; top:10px; left:10px;"></div>
</div>

This doesn't have to be the direct parent, when you set absolute positioning the element will position from the nearest ancestor with a set positioning.

parent must have position:relative; (or some other positioning apart from static) so that it's child can be positioned absolutely relative to them.

Hussein

You need to give your parent div position:relative and your child div position absolute

Check working example at http://jsfiddle.net/remYW/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!