Hca*_*tek 9 html javascript css jquery
我有一个div有两个嵌套的div.第一个孩子根据其内容有不同的高度,我希望第二个div高度是父母留下的任何东西.
<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>
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
谢谢,〜在圣地亚哥
它需要一些JavaScript.我看到你正在使用jQuery,所以这应该工作:
给你的父div一些id:
<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>
Run Code Online (Sandbox Code Playgroud)
然后在jQuery中:
$('div#parent div:last').each(function() {
var p = $(this).parent();
$(this).height(p.height() - ($(this).offset().top - p.offset().top));
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4998 次 |
| 最近记录: |