<div class="main">
<div id="box1"></div>
<div id="box2"></div>
</div>
<style lang="scss">
.main{
border:1px solid blue;
width:220px;
}
.main::after{
content:'';
clear:both;
display:block;//注意清除浮动只对block元素有效
}
#box1{
width:100px;
height: 100px;
background: red;
float:left;
}
#box2{
width:100px;
height: 100px;
float:left;
background: black;
}
</style>
通过清除浮动来撑开父元素
最新推荐文章于 2021-10-25 19:49:32 发布