带有子边距的div高度 [英] Div height with child margin

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

问题描述

我有两个div,我想让他们的高度相等:

I have 2 divs and I want to make their height equal:

var highestCol = $('#SecondColumn').height();
$('.column').first().height(highestCol);

我知道第二个div总是高于第一个div。当两个div中都有纯文本时,一切正常。但是在添加div和一些边距或填充到第二个div(总是更高)后,calculatio断裂。

I know that second div is always higher than first one. When there is plain text in both divs everything works fine. But after adding divs with some margin or padding into second div (always higher) the calculatio breaks. It takes height of higher div but ignores sum of all margins of child divs inside second column.

如何计算带有边距/ paddings的整个div?

How can I calculate full div with margins/paddings?

推荐答案

我想你想要 outerHeight(true),而不是height

I think you want outerHeight(true) rather than 'height()' to include the margins/paddings.

'true'是指包含边距。

The 'true' refers to including the margins or not.

这篇关于带有子边距的div高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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