如何使DIV占用容器div的其余高度? [英] How can I make a DIV take up the rest of the height of a container div?

查看:114
本文介绍了如何使DIV占用容器div的其余高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div与两个嵌套的div。第一个孩子具有不同的高度,取决于它的内容,我想要第二个divs高度是从父母剩下的任何。

I have a div with two nested divs. The first child has varying height depending on its content, I want the the 2nd divs height to be whatever is left over from the parent.

<div style="height:500px;">
   <div>Some Content Here</div>
   <div>This div needs to take up the rest of the space of its parent</div>
</div>

我如何做?

谢谢,
〜ck在圣地亚哥

Thanks, ~ck in San Diego

推荐答案

我看到你使用jQuery,所以这应该工作:

It requires some javascript. I see you're using jQuery, so this should work:

给你的父div一些id:

Give some id to your parent div:

<div style="height:500px;" id="parent">
    <div>Some Content Here</div>
    <div>This div needs to take up the rest of the space of its parent</div>
</div>

然后在jQuery中:

Then in jQuery:

$('div#parent div:last').each(function() {
    var p = $(this).parent();
    $(this).height(p.height() - ($(this).offset().top - p.offset().top));
});

这篇关于如何使DIV占用容器div的其余高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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