jQuery used height of Div element

I try to get the exact used Height of a div element. It should be .outerHeight() but this does not work if the last child of the div has a border bottom. I did a little example:

Html:

innerDiv1
innerDiv2

Css:

.box div{
    height:100px;
    margin-bottom:20px;
}

Code example: http://jsfiddle.net/T3b6r/4/ The used height schould be 240px (2x100px for height + 2x20px margin) but the last margin-bottom is ignored. (Margin-top is ignored completly by the way)

Did i oversee something or do i have to check each element for their margins, to get the space used by the div?

1
задан NibblyPig 27 August 2010 в 10:24
поделиться

2 ответа

Если вы поместите div-контейнер в рамку, он вернет желаемую высоту. Просто используйте рамку того же цвета, что и фон, на котором она будет находиться.

См. http://jsfiddle.net/T3b6r/7/

2
ответ дан 2 September 2019 в 21:48
поделиться

Вы используете .outerHeight(true) ? Без логического значения true поля не будут включены.

0
ответ дан 2 September 2019 в 21:48
поделиться
Другие вопросы по тегам:

Похожие вопросы: