css - 清除浮动到底该清除谁的浮动
本文介绍了css - 清除浮动到底该清除谁的浮动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
<div id="aa">#aa元素</div>
<div id="bb">
<a>a元素</a>
<p>p元素</p>
</div>
<style>
#aa{
width:100px;
height:100px;
border:red dotted 1px;
float:left;
}
div#bb{
width:500px;
border:blue dotted 2px;
margin-left:120px;
}
a{
float:left;
width:120px;
height:50px;
border:red dotted 1px;
}
p{
width:300px;
height:50px;
background-color:yellowgreen;
margin:0px;
clear:left;
}
</style>
问题是让p元素清除浮动,p元素应该清除<a>元素的浮动,但是为什么连#aa元素的浮动也清除了????
解决方案
clear:left的意思就是p的左边不允许有浮动元素,而不论这个浮动元素在哪个层级。如果你想让#bb与#aa相互不影响,应该在#bb下生成 bfc
div#bb{
width:500px;
border:blue dotted 2px;
margin-left:120px;
overflow: hidden;
}
这篇关于css - 清除浮动到底该清除谁的浮动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文