The div is a block element and all block elements have a built in padding and margins which varies by browser but can be overidden with css and even set to negative values.
Top and Bottom values for padding are cumulative. Top and Bottom values for margins are not.
In this example, them amount of space between the two div's is 10 ems as padding is cumulative
<div style="padding: 5em;">Div One</div> <div style="padding: 5em;">Div Two</div> |
In this example, the amount os space between the divs is 5 em as the top amd bottom margins overlap
<div style="margin: 5em;">Div One</div> <div style="margin: 5em;">Div Two</div> |
When specifying margins or padding (e.g. padding: 0 0 0 0; -
- If 1 value is used, all borders use it
- If 2 values are used, the first is the Top+Bottom, the second is Left+Right
- If 3 vaules are used, the first is the Top, the second Left+Right, and the third the bottom.
- If 4 values are used, they correspond to TRBL.
In your case, using absolute positioning, you may want to set the padding to 0 and just use the margins for positioning - e.g.
<div style="padding: 0; margin: T R B L">The Content</div> |