Tuesday, June 23, 2015

CSS margin vs padding

Margin is outside of the block, e.g. div
padding is inside of the block>





Margin is that margins auto-collapse, and padding doesn't.
The right margin of the left element is 10px, the left margin of the right element is 10px, the space between left and right is 10px.
The right padding of the left element is 10px, the left padding of the right element is 10px, the space between left and right is 20px.

For JQuery,
$("Content Selector").height() only returns the height of the content, does not include padding, border and margin.
$("Content Selector").outerHeight() returns the height including content, padding and border, but not margine.
$("Content Selector").outerHeight(true) returns the height including content, padding, border and margine.

http://api.jquery.com/outerheight/

No comments:

Post a Comment