1

Is there any way in css to position an Element something like absolute (in relation to the parent element), e. g. at the bottom of its parent element, but have it still staying in the documentflow?

E. g. that an element, positioned relative above the element, by getting more height, pushing the "absolute" element downwards while the container-element's height is also increaseing at the time the relative element would "touch" the absolute one but on the otherhand the "absolute"-elements position and the container-elements' height won't change if there's no "touch"?

Or is this just an impossible task and can only be done with javascript?

4

1 回答 1

2

如果您强制,您可以相对于父级定位绝对 div

position: relative;

在父 div 上。否则绝对将相对于文档定位。

<div style="position:relative;">
    <div style="position:absolute; top:10px; right:10px;">
         ................
    </div>
</div>

这不会有你想要的拉伸效果,但是如果你想要你描述的那种块行为,浮动和应用边距有什么问题?

<div style="position:relative;">
    <div style="float: right; margin-top:10px; margin-right:10px;">
         ................
    </div>
    <div>text</div>
</div>

只要正确清除父div,那么无论是上面div的浮动内容还是正常内容,都可以决定父元素的高度。

如果您还需要与底部对齐,则可以查看 display: table-cell 作为选项(不适用于 IE7)

于 2012-10-25T16:50:15.937 回答