Html 我怎样才能把两个div放在同一条线上?

Html 我怎样才能把两个div放在同一条线上?,html,Html,我有两个div,我想将它们对齐在同一行中。html代码是: <div class="box"> <div class="boxleft"> </div> <div class="boxright"> </div> </div> 在当今大多数现代浏览器上,显示:表格单元格是浮动的更好选择。在当今大多数现代浏览器上,显示:表格单元格是浮动的更好选择。您可以使用 display:inline-block; display: t

我有两个div,我想将它们对齐在同一行中。html代码是:

<div class="box">
<div class="boxleft"> </div>
<div class="boxright"> </div>
</div>

在当今大多数现代浏览器上,显示:表格单元格是浮动的更好选择。

在当今大多数现代浏览器上,显示:表格单元格是浮动的更好选择。

您可以使用

display:inline-block;
display: table-cell
clear: both

或者根据最新的浏览器,您可以使用

display:inline-block;
display: table-cell
clear: both
或者你可以使用

display:inline-block;
display: table-cell
clear: both
你可以用

display:inline-block;
display: table-cell
clear: both

或者根据最新的浏览器,您可以使用

display:inline-block;
display: table-cell
clear: both
或者你可以使用

display:inline-block;
display: table-cell
clear: both

Float:left
应该根据父
框的宽度以及
boxleft
boxright
的宽度来执行此操作。如果父
具有
宽度:500px
boxleft
boxright
都具有
宽度:250px;浮动:左。你应该没事。

Float:left
应该根据父
box
的宽度以及
boxleft
boxright
的宽度来完成。如果父
具有
宽度:500px
boxleft
boxright
都具有
宽度:250px;浮动:左。你应该没事。

看看css属性
float:left
clear:all


查看css属性
float:left
clear:all

如果你不是一个“CSS人”,看看。使用bootstrap,将两个div放在同一行上,方法如下:

<div class="row-fluid box">
    <div class="span6 boxleft"></div>
    <div class="span6 boxright"></div>
</div>

如果你不是一个“CSS人”,看看。使用bootstrap,将两个div放在同一行上,方法如下:

<div class="row-fluid box">
    <div class="span6 boxleft"></div>
    <div class="span6 boxright"></div>
</div>

我在每个背景上添加了一些颜色,以清楚地表明,您可能缺少每个元素的宽度和高度

.boxleft , .boxright {
    float : left;
    width : 200px;
    height : 100px;
    margin : 10px;
}
.boxleft {
    background : yellow;
}
.boxright {
    background : blue;
}

为了清楚起见,我在每个背景上都添加了一些颜色,您可能缺少每个元素的宽度和高度

.boxleft , .boxright {
    float : left;
    width : 200px;
    height : 100px;
    margin : 10px;
}
.boxleft {
    background : yellow;
}
.boxright {
    background : blue;
}

您需要通过父容器上的clearfix清除浮动

.box {
    width: 956px;
    background: #584231;
}

/* clearfix */
.box:after {
     content: '';
     display: block;
     clear: both;
     visibility: hidden;
     line-height: 0;
     height: 0;
}

.boxleft {
    width: 704px;
    border-right: 2px solid black;
    float: left;
}

.boxright {
    width: 250px;
    float: right;
}
边框为您的divs宽度增加了2px。这就是我用704px指定它的原因


inline block
用作左右框的
display
,也可以使用

您需要通过父容器上的clearfix清除浮动

.box {
    width: 956px;
    background: #584231;
}

/* clearfix */
.box:after {
     content: '';
     display: block;
     clear: both;
     visibility: hidden;
     line-height: 0;
     height: 0;
}

.boxleft {
    width: 704px;
    border-right: 2px solid black;
    float: left;
}

.boxright {
    width: 250px;
    float: right;
}
边框为您的divs宽度增加了2px。这就是我用704px指定它的原因


inline block
用作左右框的
display
,也可以使用

内联块
应该可以工作;CSS的其余部分是什么?
内联块
应该可以工作;你的CSS的其余部分是什么?你不需要指定
width
height
来使
float
工作。你不需要指定
width
height
来使
float
工作。