Difference between margin and padding?

后端 未结 22 2284
广开言路
广开言路 2020-11-22 12:58

What exactly is the difference between margin and padding in CSS? It really doesn\'t seem to serve much purpose. Could you give me an examp

22条回答
  •  甜味超标
    2020-11-22 13:16

    One of the key differences between margin and padding is not mentioned in any of the answers: clickability and hover detection

    Increasing the padding increases the effective size of the element. Sometimes I have a smallish icon that I don't want to make visibly larger but the user still needs to interact with that icon. I increase the icon's padding to give it a larger footprint for clicks and hover. Increasing the icon's margin will not have the same effect.

    An answer to another question on this topic gives an example.

提交回复
热议问题