根据另一个div的高度设置一个div的高度 [英] Setting the height of one div based on another divs height

查看:454
本文介绍了根据另一个div的高度设置一个div的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两列div布局

<div id="site-wrapper">
<div id="leftSidebar">


</div>


<div id="rightSide">

</div>
</div>

我的js

 $('#leftSidebar').height($('#rightSide').height());

但是在IE7中,它在底部添加了一块空白.我的jQuery正确吗?

However in IE7 it's adding a chunk of white space at the bottom. Is my jquery correct?

推荐答案

是的,outerHeight应该为您做到这一点.

Yes, outerHeight should do this for you.

http://api.jquery.com/outerHeight 说:

.outerHeight()计算中始终包括顶部和底部的填充以及边框.如果includeMargin参数设置为true,则还包括边距(顶部和底部).

The top and bottom padding and border are always included in the .outerHeight() calculation; if the includeMargin argument is set to true, the margin (top and bottom) is also included.

因此,如果您有边距:

$('#leftSidebar').height($('#rightSide').outerHeight(true));

这篇关于根据另一个div的高度设置一个div的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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