Search code examples
cssjquery-uijquery-ui-tabsjquery-ui-sortablejquery-ui-theme

Why does 10px + 10px = 10px?


I have the following script where the margin for the . portlet class is behaving strangely:

http://jsfiddle.net/mYx5y/19/

it should be adding 10px around each portlet, which should mean a gap of 20px between portlets. For some reason, I am only getting 20px if a portlet has a widget to the right or left of itself, but only 10px if the portlet has another portlet above or below it.

Why am I getting 10px vertically?


Solution

  • Because margins don't add up, they collapse. If you have two elements A and B, A margin=10px and B margin=15px, the spacing between A and B will be 15px.

    Two solutions:

    1. Use margin-bottom: 20px, margin-top: 0px
    2. Wrap them into a container and apply padding: 10px 0;