<style type="text/css">
.outer{
background-color: #1E9FFF;
margin: 100px;
}
.inner{
background-color: #FFFF00;
margin: 50px;
height: 50px;
}
</style>
<body>
<div class="outer">
<div class="inner"></div>
</div>
</body>
显示出来的 蓝色样式 和 黄色样式 的 外边距重叠
解决方法:
1、给蓝色区域添加边框,就可以解决。
<style type="text/css">
.outer{
background-color: #1E9FFF;
margin: 100px;
border: 1px solid #1E9FFF;
}
</style>
2、使用overflow:hidden也可以解决。
<style>
.outer{
background-color: #1E9FFF;
margin: 100px;
overflow:hidden;
}
</style>
(这里就不放图片了,和第一种解决方案一样)
3、给父元素和子元素增加宽度,子元素设置为内联块。
<style type="text/css">
.outer{
background-color: #1E9FFF;
margin: 100px;
width: 1000px;
}
.inner{
background-color: #FFFF00;
margin: 50px;
height: 50px;
width: 900px;
display: inline-block;
}
</style>
(后续待添加……)