我知道如何让2个divs并排浮动,简单地浮动一个到左边,另一个到右边。
但是如何用3个div来做这个,或者我应该只用表来做这个目的吗?
我知道如何让2个divs并排浮动,简单地浮动一个到左边,另一个到右边。
但是如何用3个div来做这个,或者我应该只用表来做这个目的吗?
当前回答
三次跳水都向左飘。像在这里:
.first-div {
width:370px;
height:150px;
float:left;
background-color:pink;
}
.second-div {
width:370px;
height:150px;
float:left;
background-color:blue;
}
.third-div {
width:370px;
height:150px;
float:left;
background-color:purple;
}
其他回答
我没有看到bootstrap的答案,所以不管怎样
<div class="col-xs-4">Left Div</div>
<div class="col-xs-4">Middle Div</div>
<div class="col-xs-4">Right Div</div>
<br style="clear: both;" />
让Bootstrap算出百分比。 以防万一,我想把两个都清除掉。
只要给它们一个宽度和float: left;,这里有一个例子:
<div style="width: 500px;">
<div style="float: left; width: 200px;">Left Stuff</div>
<div style="float: left; width: 100px;">Middle Stuff</div>
<div style="float: left; width: 200px;">Right Stuff</div>
<br style="clear: left;" />
</div>
我通常只是把第一个浮动到左边,第二个浮动到右边。第三个自动在它们之间对齐。
<div style="float: left;">Column 1</div>
<div style="float: right;">Column 3</div>
<div>Column 2</div>
@Leniel这个方法很好,但是你需要为所有浮动div添加宽度。我会说,让它们宽度相等或分配固定宽度。类似的
.content-wrapper > div { width:33.3%; }
您可以为每个div分配类名,而不是添加内联样式,这不是一个好的实践。
请确保使用clearfix div或clear div,以避免下面的内容仍然低于这些div。
你可以在这里找到如何使用clearfix div的详细信息
三次跳水都向左飘。像在这里:
.first-div {
width:370px;
height:150px;
float:left;
background-color:pink;
}
.second-div {
width:370px;
height:150px;
float:left;
background-color:blue;
}
.third-div {
width:370px;
height:150px;
float:left;
background-color:purple;
}