Position DIV relative to another DIV?

匿名 (未验证) 提交于 2019-12-03 02:45:02

问题:

Is it possible to position a DIV relative to another DIV? I imagine this can be done by first placing it inside of the reference DIV, and then using position: relative. However, I can't figure out how to do this without affecting the contents of the reference DIV. How can I do this properly?

See: http://jsfiddle.net/CDmGQ

Thanks! =)

回答1:

First set position of the parent DIV to relative (specifying the offset, i.e. left, top etc. is not necessary) and then apply position: absolute to the child DIV with the offset you want.
It's simple and should do the trick well.



回答2:

You need to set postion:relative of outer DIV and position:absolute of inner div.
Try this. Here is the Demo



回答3:

You want to use position: absolute while inside the other div.

DEMO



回答4:

you can use position:relative; inside #one div and position:absolute inside #two div. you can see it



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