CSS, nested divs & margins vs. padding

后端 未结 7 2073
攒了一身酷
攒了一身酷 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:19

    Paddings and margins gives the same effect, Except in the following cases (I might miss some):

    1. You have some kind of background properties. Margins won't get them.
    2. You have a border
    3. You use TD (no margins)
    4. Two nested items, The margins are collapsed together, where paddings not.
    5. (need to check this one) They probably affect the width and height of the element differently. (If some one knows better, pls edit this).

提交回复
热议问题