Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery outerHeight doesn't work properly?

Tags:

jquery

height

Link's style:

#carousel ul li {
    display: inline-block;
    border: solid 1px red;
    margin: 50px 25px 50px 25px;
    width: 350px;
    height: 300px;
}

jQuery's code:

var height = $("#carousel ul li").outerHeight(); 

document.write(height);

And it says height of the element is 302px ! Why? It's maybe 302 with borders, but shouldn't outerHeight show 300 + 2 + 100 (both top and bottom margins are 50 px).

I'm confused.

Thanks.

like image 346
fomicz Avatar asked Sep 23 '10 20:09

fomicz


2 Answers

By default outerHeight() does not include margins. Pass true to include margins in the calculation like this:

var height = $("#carousel ul li").outerHeight(true);
like image 144
smabbott Avatar answered Oct 29 '22 03:10

smabbott


Nope. margin isn't counted. height, border and padding is.

if your li contains block elements with margin that is counted though.

like image 25
thomasmalt Avatar answered Oct 29 '22 02:10

thomasmalt