Difference between margin and padding?

后端 未结 22 1965
广开言路
广开言路 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:17

    Margin is applied to the outside of you element hence effecting how far your element is away from other elements.

    Padding is applied to the inside of your element hence effecting how far your element's content is away from the border.

    Also, using margin will not affect your element's dimensions whereas padding will make your elements dimensions (set height + padding) so for example if you have a 100x100px div with a 5 px padding, your div will actually be 105x105px

提交回复
热议问题