i totally understand the box model. this question is more about trying to pin down a semantic methodology regarding when to use margins and when to use padding.
her
Vertical padding on the division - because if I decided I wanted a different amount of vertical space in between the multiple paragraphs I'd use bottom margins, and the top/bottom padding of the enclosing division pretty much will always stay intact assuming you just have staticly positioned elements inside.
It depends on what you're trying to accomplish visually. Would container
have other child elements which might hang over into the gutter on either side of the paragraph? If so, a margin makes more sense. But if container
should have a 12-pixel gutter for all elements, period, it makes the most sense to use the padding to avoid having to apply margins to multiple element sets.
Generally speaking you always want paragraphs to have vertical margins to ensure consistent paragraph leading.
Paddings and margins gives the same effect, Except in the following cases (I might miss some):
Personally, I prefer option A. Why? Say now I have to add other HTML elements into the div and I want the padding to be maintained, I would not have to add other rules to my CSS files to get it working.
The difference is where the border sits.
The border sits SMACK DAB in the middle of the margins and padding. If you specify margins, that is white space OUTSIDE the border.
If you specify padding, that is white space INSIDE the border (pushes the border further out from the element)
Can't show you here due to css stripping, but try this out:
<body style="background-color: #aaa"> <p style="background-color: #aee; margin: 40px; padding: 40px; border: solid 2px black;"> i have margins, padding and a border. </p> <p style="background-color: #aee; margin: 40px; padding: 0; border: solid 2px black;"> i have margins, and a border. </p> <p style="background-color: #aee; margin: 0; padding: 40px; border: solid 2px black;"> i have padding and a border. </p> </body>
other stuff!
padding brings in background color of the element, margins are basically transparent
some elements ( like td ) seem to ignore margins, while they respond to changes in padding
This is a bug in css, here are examples:
http://creexe.zxq.net/div-issue-padding.html = padding issue
http://creexe.zxq.net/div-issue-margin.html = margin issue
the red and green div tags in the examples were created by the css property TOP,but it has its own disadvantages athat TOP,BOTTOM etc works only when the position of the div tag is Absolute and relative, but not static