padding属性用于设置内边距,即边框与内容之间的距离。
padding-top,padding-left,padding-right,padding-bottom
或复合写法

没有设置padding时

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. div {
  10. width: 200px;
  11. height: 200px;
  12. background-color: blue;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <div>
  18. WinFangWinFang <br>
  19. WinFangWinFang <br>
  20. </div>
  21. </body>
  22. </html>

效果图
image.png

设置了padding后

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <style>
    div {
      width: 200px;
      height: 200px;
      background-color: blue;
      padding-left: 20px;
      padding-top: 20px;
    }
  </style>
</head>

<body>
  <div>
    WinFangWinFang <br>
    WinFangWinFang <br>
  </div>
</body>

</html>

效果图
image.png