How to float 3 divs side by side using CSS?

2019-01-01 16:44发布

I know how to make 2 divs float side by side, simply float one to the left and the other to the right.

But how to do this with 3 divs or should I just use tables for this purpose?

标签: css css-float
15条回答
牵手、夕阳
2楼-- · 2019-01-01 17:37

Just give them a width and float: left;, here's an example:

<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>
查看更多
残风、尘缘若梦
3楼-- · 2019-01-01 17:38

I didn't see the bootstrap answer, so for what's it's worth:

<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;" />

let Bootstrap figure out the percentages. I like to clear both, just in case.

查看更多
呛了眼睛熬了心
4楼-- · 2019-01-01 17:40

Float all three divs to the left. Like here:

.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;
}
查看更多
登录 后发表回答