<div class="father">
<div class="son-left">
</div>
<div class="son-right">
</div>
</div>
.father{
width: 500px;
border: 1px solid red;
background-color: orange;
height: 300px;
}
.son-left .son-right{
width: 200px;
height: 300px;
background: blueviolet;
float: left;
}
.son-left{
float:left
}
.son-right{
float: right;
}
<div class="father">
<div class="son-left">
</div>
<div class="son-right">
</div>
<div class="clean">
</div>
</div>
.father{
width: 500px;
border: 1px solid red;
background-color: orange;
}
.son-left .son-right{
width: 200px;
height: 300px;
background: blueviolet;
float: left;
}
.son-left{
float:left
}
.son-right{
float: right;
}
.clean{
clear: both;
}
</style>
<div class="father">
<div class="son-left">
</div>
<div class="son-right">
</div>
<div class="clean">
</div>
</div>
.father{
width: 500px;
border: 1px solid red;
background-color: orange;
overflow: hidden;
}
.son-left .son-right{
width: 200px;
height: 300px;
background: blueviolet;
float: left;
}
.son-left{
float:left
}
.son-right{
float: right;
}
因为overflow:hidden属性相当于是让父级紧贴内容,这样即可紧贴其对象内内容(包括使用float的div盒子),从而实现了清除浮动
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。