1.首先创建三个盒子,我们首先想到的是去修改第二个盒子和第三个的上外边距,左外边距
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{
margin: 0;
padding: 0;
}
.grandFather{
width: 500px;
height: 500px;
background-color: blue;
}
.father{
width: 300px;
height: 300px;
background-color: red;
margin-top: 100px;
margin-left: 100px;
}
.son{
width: 150px;
height: 150px;
background-color: green;
margin-top: 10px;
margin-left: 10px;
}
</style>
</head>
<body>
<div class="grandFather">
<div class="father">
<div class="son"></div>
</div>
</div>
</body>
</html>
问题:三个盒子上面还是对齐的
2.解决办法1:
修改父盒子的上内边距,左内边距
3.解决方法2:
给父元素添加 overflow:hidden