html - 使 float div 填充空白

标签 html css css-float

我有 3 个 div 的问题,当一个 div 比另一个 div 长时,它会产生一些空白。
我希望空白消失,div 连接。
这就是我现在拥有的:

.one{
background: lightgreen;
height: 300px;
width:100px;
float: left;
margin: 5px;
}
.two{
background: brown;
height: 500px;
width: 100px;
float: left;
margin: 5px;
}
.main{
width: 220px;

}
.info{
background: orange;
height: 200px;
width:100px;
float: left;
margin: 5px;

}
<div class='main'>
<div class='info'>

to this one

</div>
<div class='two'>



</div>
<div class='two'>
this one should be up


</div>
<div class='two'>



</div>
<div class='one'>



</div>
</div>

我有这些类的唯一原因是因为我想展示我的问题的一个例子,实际上所有的 div 都有相同的类。
谁能帮我解决这个问题?

my problem 正如你在我的图片中看到的,底部的 div 没有连接到它上面的那个。
所有的 div 都有 float: left;

最佳答案

这是不可能的,当类 .two 向左浮动时。 您必须为 .two 类使用 float:right

.one{
background: lightgreen;
height: 300px;
width:100px;
float: left;
margin: 5px;
}
.two{
background: brown;
height: 500px;
width: 100px;
float: right;
margin: 5px;
}
.main{
width: 220px;

}
<div class='main'>
<div class='one'>

to this one

</div>
<div class='two'>



</div>
<div class='one'>
this one should be up


</div>
</div>

关于html - 使 float div 填充空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50566542/

相关文章:

javascript - 使用 javascript 动态更改表行类名称

javascript - 可编辑的组合框,带有显示弹出窗口的按钮

javascript - 如何使用 Javascript 以外的语言操作 DOM?

html - CSS 删除图片下方的文字

javascript - 使站点不出现在历史记录中(通过代码,而不是用户)

css - 不能将输入提交按钮上的文本样式设置为粗体?

html - 如何将图像对齐到 ionic 页面的中心

html - 如何在网页上并排放置三个 div 元素

html - float div 影响我屏幕中其他 div 的高度

html - 复选框打破无表表单布局