撑开盒子的情况
<!DOCTYPE html>
<html lang="en">
<head>
<style type="text/css">
.father {
width: 300px;
height: 300px;
background-color: orange;
padding-left: 100px; ////因为盒子宽度给定,padding会撑开盒子
}
.son {
background-color: green;
}
</style>
</head>
<body>
<div class="father">
<div class="son">
123
</div>
</div>
</body>
</html>
没撑开盒子情况
<!DOCTYPE html>
<html lang="en">
<head>
<style type="text/css">
.father {
width: 300px;
height: 300px;
background-color: orange;
}
.son {
background-color: green;
padding-left: 100px; //没有宽度,使用默认,盒子不会撑开
}
</style>
</head>
<body>
<div class="father">
<div class="son">
123
</div>
</div>
</body>
</html>
撑开盒子情况
<!DOCTYPE html>
<html lang="en">
<head>
<style type="text/css">
.father {
width: 300px;
height: 300px;
background-color: orange;
}
.son {
width: 300px;
background-color: green;
padding-left: 100px;
}
</style>
</head>
<body>
<div class="father">
<div class="son">
123
</div>
</div>
</body>
</html>
网友评论