位置DIV在固定div下面,可变高度 [英] Position DIV below fixed div with variable height

查看:215
本文介绍了位置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.

这篇关于位置DIV在固定div下面,可变高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆