<style>
.root {
width: 300px;
height: 300px;
background-color: beige;
/* 第一种方案 */
/* position: absolute; */
/* 第二种方案 */
/* overflow: hidden; */
/* 第三种方案 */
/* padding-top: 1px;
/* 第五种解决 */
/* border: 1px;
height: 299px; */
}
.a {
width: 200px;
height: 200px;
background-color: aliceblue;
margin-top: 30px;
/* 第四种方法 我喜欢 */
display: inline-block;
}
.b {
width: 100px;
height: 100px;
background-color: rgb(185, 215, 241);
margin-top: 30px;
}
</style>
</head>
<body>
<div class="root">
<div class="a">
<div class="b">b</div>
</div>
</div>
</body>
参考:https://www.jb51.net/css/544072.html
[css] 请描述margin边界叠加是什么及解决方案_歌谣的博客-优快云博客