您的位置:首页 > Web前端 > CSS

css div position to parent

2015-06-08 16:19 603 查看
To position an element "fixed" relative to a parent element, you want
position:absolute
on the child element, and any position mode other than the default or static on your parent element.

For example:

#parentDiv { position:relative; }
#childDiv { position:absolute; left:50px; top:20px; }

This will position
childDiv
element 50 pixels left and 20 pixels down relative to parentDiv's position.

To position an element "fixed" relative to the window, you want
position:fixed
, and can use
top:
,
left:
,
right:
, and
bottom:
to position as you see fit.

For example:

#yourDiv { position:fixed; bottom:40px; right:40px; }

This will position
yourDiv
fixed relative to the web browser window, 40 pixels from the bottom edge and 40 pixels from the right edge.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: