<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>盒子中的不可避免的bug</title>
<style>
/*这个bug就是两个盒子嵌套,小盒子用margin外边距无法与大盒子隔离开距离,还会让大盒子往下移*/
.father{
background-color: yellow;
width: 200px;
height: 200px;
overflow: hidden;
/*
方法1.
可以为父元素添加
overflow: hidden;
这是解决办法2.
用大盒子设置padding内边距即可,但是会把盒子撑大。
padding-left: 30px;
padding-top: 30px;
这是解决办法3.
设置大盒子的边框
border-top: 1px solid yellow ;
*/
}
.son{
background-color: cornflowerblue;
width: 100px;
height: 100px;
margin-top: 30px;
}
</style>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
</body>
</html>