我知道如何让2个divs并排浮动,简单地浮动一个到左边,另一个到右边。
但是如何用3个div来做这个,或者我应该只用表来做这个目的吗?
我知道如何让2个divs并排浮动,简单地浮动一个到左边,另一个到右边。
但是如何用3个div来做这个,或者我应该只用表来做这个目的吗?
当前回答
我更喜欢这种方法,浮动在旧版本的IE中支持很差(真的吗?…)
.column-left{ position:absolute; left: 0px; width: 33.3%; background: red; }
.column-right{position:absolute; left:66.6%; width: 33.3%; background: green; }
.column-center{ position:absolute; left:33.3%; width: 33.3%; background: yellow; }
更新: 当然,要使用这种技术,由于绝对定位,你需要在容器上封装div,并做后处理来定义if的高度,类似这样:
jQuery(document).ready(function(){
jQuery('.main').height( Math.max (
jQuery('.column-left').height(),
jQuery('.column-right').height(),
jQuery('.column-center').height())
);
});
这不是世界上最神奇的东西,但至少不会砸到老的ie。
其他回答
<br style="clear: left;" />
有人在上面发布的代码,成功了!! 当我在关闭容器DIV之前粘贴它时,它有助于清除所有后续DIVs与我在顶部并排创建的DIVs重叠!
<div>
<div class="left"></div>
<div class="left"></div>
...
...
<div class="left"></div>
<!-- then magic trick comes here -->
<br style="clear: left;" />
</div>
tadaa ! !:)
我通常只是把第一个浮动到左边,第二个浮动到右边。第三个自动在它们之间对齐。
<div style="float: left;">Column 1</div>
<div style="float: right;">Column 3</div>
<div>Column 2</div>
display: table;如果文本需要显示,如果在同一行
换句话说;如果在每个<div>文本的垂直对齐需要是相同的,一个可以尝试现代复古回到过去的有点有争议的表格样式:
.container {display: table;}
div {display: table-cell;}
事实证明,这对于在Pandoc中格式化csl风格的引用非常有用,如下所示:
div.csl-bib-body {}
div.csl-entry {
margin-top: 1rem;
display: table;
}
div.csl-left-margin {
display: table-cell;
}
div.csl-right-inline {
padding-left: 1ex;
display: table-cell;
}
引文编号div和引文数据div现在显示在完全相同的高度。
尝试在样式中添加“display: block”
<style>
.left{
display: block;
float:left;
width:33%;
}
</style>
<div class="left">...</div>
<div class="left">...</div>
<div class="left">...</div>
我没有看到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算出百分比。 以防万一,我想把两个都清除掉。