panding不会撑开盒子的情况

如果一个盒子没有给定宽度/高度,则padding 不会影响本盒子大小

下面代码son会向右移动20px但是son的宽度不变 如果想改变他的宽度需要给他加上一个宽度但是没必要

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .father {
            width: 200px;
            height: 200px;
            background-color: red;
        }
        .son {
           padding-left:20px;
        }
    </style>
</head>
<body>
    <div class="father">
        <div class="son">123</div>
    </div>
  
</body>
</html>
posted @ 2019-12-14 21:36  handsomehe  阅读(713)  评论(0编辑  收藏  举报