CSS, nested divs & margins vs. padding

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

    Personally, I'd go with option a of #container {padding: 12px;} because it makes amply clear that all child elements must stay 12px away from the border of this div.

    If I want other elements to stay more than 12px away from the #container's border, then I apply as much more margin to that element.

    Cheers!

    0 讨论(0)
提交回复
热议问题