what is the padding's role on the css and html

This question already has an answer here:

  • When to use margin vs padding in CSS [closed] 18 answers

  • As you can see in the image (shared by Josh) :

    Say you have an element c with parent p.

  • Padding : When applied to p, adds space inside p, but outside c.
  • Padding : When applied to c, adds space inside c.
  • Margin : When applied to c, adds space outside c, but inside p.
  • Margin : When applied to p, adds space outside p, but inside p's parent.
  • You may notice that 1st & 3rd case look alike when only p & c are considered.


    Padding is the distance from the outer border of an element to the inner part which contains the children.

    +------------+
    |  (Padding) |
    |  +------+  |<--- Outer Border
    |  |(con- |  |
    |  | tent)|  |
    

    Note however, that in browsers like Firefox and Chrome by default the padding gets added to the width of the element.

    链接地址: http://www.djcxy.com/p/29420.html

    上一篇: 在CSS中何时使用填充以及何时使用边距

    下一篇: 什么是填充在CSS和HTML上的作用