位置DIV在固定div下面,可变高度

问题描述:

这里是问题:
让我说我有这样的:

Here is the Problem: Lets say I have something like this:

<div id="leftcontainer">
    <div id="top" style="position:fixed"></div>
    <div id="below"></div>
</div>

我想在#top div下面有#below div, -top,因为#top div将有不同的大小。
另外,#below div的大小可以不同,应该滚动到#top div下面。

And I would like to have the #below div, below the #top div, but not use margin-top, since the #top div will have different sizes. Also, the #below div can vary in size, and should scroll beneath the #top div.

有没有人知道如何实现呢?
Greets - Chris

Does anybody have an idea how to realize that? Greets - Chris

这是相当简单的jQuery if

This is fairly simple with jQuery if the top div's height is fixed after the page renders.

$(document).ready(function() {
    $('#below').css('top', $('#top').outerHeight());
});

这将指定下面元素的css top属性等于顶级元素的完整高度。其他布局因素可能导致顶部不是正确的值,在这种情况下,你必须确定正确的方式来识别顶部值,但主体是相同的,在简单的情况下,这将工作,而不修改。

That will assign the css top property of the below element equal to the full height of the top element. Other layout factors may cause that to not be the correct value for top, in which case you'll have to determine the correct way to identify the top value, but the principal is the same and in the simple case, this will work without modification.