Difference between margin and padding?

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

    Padding

    Padding is a CSS property that defines the space between an element content and its border (if it has a border). If an element has a border around it, padding will give space from that border to the element content which appears in that border. If an element does not have a border around it, then adding padding has no effect at all on that element, because there is no border to give space from.

    Margin

    Margin is a CSS property that defines the space of outside of an element to its next outside element.

    Margin affects elements that both have or do not have borders. If an element has a border, margin defines the space from this border to the next outer element. If an element does not have a border, then margin defines the space from the element content to the next outer element.

    Difference Between Padding and Margin

    So the difference between margin and padding is that while padding deals with the inner space, margin deals with the outer space to the next outer element.

提交回复
热议问题