CSS, nested divs & margins vs. padding

后端 未结 7 2230
攒了一身酷
攒了一身酷 2021-01-13 16:10

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

7条回答
  •  忘掉有多难
    2021-01-13 16:15

    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.

提交回复
热议问题