How should CSS 'margin' and 'padding' be used for vertical inter-paragraph spacing:
- Can the vertical space between paragraphs be defined using padding and/or using margins?
- If it can be done with either, then which is the better or more normal one to use?
- Do you tend to define non-zero padding and non-zero margins, and if so then how much of each?
The Example of margins, padding, and borders explains in theory what the difference is between margin and padding: I'm questioning how much of each to use in practice, to render a normal, good-looking page.
Secondly, given markup like the following ...
<p>Paragraph.</p>
<ul>
<li>List item.</li>
<li>Another list item.
<p>List paragraph.</p>
</li>
</ul>
If you want equal vertical space between each paragraph and/or list item, then:
- Would you tend to define the
<ul>
as having zero margin+padding of its own? - Or would the
<ul>
normally have non-zero margin, which would then have no effect because this margin will be collapsed with the margin of the<li>
within it and of the<p>
which precedes it?
Thirdly (and I'm not sure whether I ought to ask this third question), the specification for collapsing margins says, "If the top and bottom margins of a box are adjoining, then it is possible for margins to collapse through it." If I have an empty paragraph like the following one in the middle ...
<p>Hello</p>
<p></p>
<p>World</p>
... then I'd expect to see this as an empty paragraph, i.e. with an extra amount of vertical space between the Hello
and the World
:
- What would prevent this empty paragraph's margins from collapsing, and the empty paragraph therefore being invisible: is it non-zero padding which does this?
- In what scenario is it useful for a box to have adjoining top and bottom margins which collapse?
Answers to any or all of these three questions would be welcome.
I'm not especially interested in IE-specific box model problems at the moment: instead I want to know about how to use the standard.