浮动的框可以向左或向右移动,直到它的外边缘碰到包含框或另一个浮动框的边框为止。
由于浮动框不在文档的普通流中,所以文档的普通流中的块框表现得就像浮动框不存在一样。
请看下图,当把框 1 向右浮动时,它脱离文档流并且向右移动,直到它的右边缘碰到包含框的右边缘:
如果把所有三个框都向左移动,那么框 1 向左浮动直到碰到包含框,另外两个框向左浮动直到碰到前一个浮动框。
<view class='cls1'>
<view class='fk1'>区块1 </view>
<view class='fk2'>区块2 </view><!--将该区块向右浮动-->
<view class='fk3'>区块3 </view>
</view>
<view class='cls2'><!--定义向左浮动-->
<view class='fk21'>区块21 </view>
<view class='fk22'>区块22 </view><!--定义向右浮动-->
<view class='fk23'>区块23 </view>
</view>
<view class='cls3'>
<view class='fk31'>区块31 </view>
<view class='fk32'>区块32 </view><!--定义向右浮动-->
<view class='fk33'>区块33 </view>
</view>
<view class='cls4'>
<view class='fk41'>区块41 </view>
<view class='fk42'>区块42 </view><!--定义向左浮动-->
<view class='fk43'>区块43 </view>
</view>
.cls1{
padding: 10px;
}
.fk1{
width: 50px;
height: 50px;
background-color: gainsboro;
}
.fk2{
width: 50px;
height: 50px;
background-color: antiquewhite;
float: right;/*向右浮动*/
}
.fk3{
width: 50px;
height: 50px;
background-color: gray;
}
.cls2{
float: left;/*向左浮动*/
}
.fk21{
width: 50px;
height: 50px;
background-color: gainsboro;
display: inline-block;
}
.fk22{
width: 50px;
height: 50px;
background-color: antiquewhite;
float: right;/*向右浮动*/
display: inline-block;
}
.fk23{
width: 50px;
height: 50px;
background-color: gray;
display: inline-block;
}
.cls3{
clear: both;
padding: 10px;
}
.fk31{
width: 50px;
height: 50px;
background-color: gainsboro;
display: inline-block;
}
.fk32{
width: 50px;
height: 50px;
background-color: antiquewhite;
float: right;/*向右浮动*/
display: inline-block;
}
.fk33{
width: 50px;
height: 50px;
background-color: gray;
display: inline-block;
}
.cls4{
clear: both;
padding: 10px;
}
.fk41{
width: 50px;
height: 50px;
background-color: gainsboro;
display: inline-block;
}
.fk42{
width: 50px;
height: 50px;
background-color: antiquewhite;
display: inline-block;
float: left;/*向左浮动*/
}
.fk43{
width: 50px;
height: 50px;
background-color: gray;
display: inline-block;
}
效果如下图