我需要展示一组div,这些div的高度可能不同,但需要无缝连接在一起显示。以下是一个例子:
如您所见,当一个元素向左浮动并且位置相邻时会产生一个空白间隙,直到下一个浮动元素出现。反之则不会发生。我找不到解决方法,因为我使用javascript过滤某些元素(div),所以无法创建两个不同的列。
以下是html/css代码:
有什么办法可以让Float1和Float3之间没有空白间隔?
![Example divs](https://istack.dev59.com/8tSLd.webp)
以下是html/css代码:
<div style="width: 200px;">
<div style="float: left; width: 50%; background-color: green;">
<p>Float1</p>
</div>
<div style="float: left; width: 50%; background-color: blue;">
<p>Float2</p>
<p>expanded</p>
</div>
<div style="float: left; width: 50%; background-color: yellow;">
<p>Float3</p>
<p>expanded</p>
</div>
<div style="float: left; width: 50%; background-color: gray;">
<p>Float4</p>
</div>
<div style="float: left; width: 50%; background-color: red;">
<p>Float5</p>
</div>
</div>
有什么办法可以让Float1和Float3之间没有空白间隔?