简体   繁体   English

将div彼此堆叠成两行,没有空格

[英]Stack divs on top of each other in 2 rows without whitespace

I really need your help on this one: 我真的需要您的帮助:

Right now I have divs just on top of each other, filled dynamically with diverse contents so the heights are changing. 现在,我的div彼此重叠,并动态填充各种内容,因此高度在变化。

What I want to do now is to place them in 2 rows. 我现在要做的是将它们放置在两行中。 With a fixed width and "float:left" this kinda works already. 具有固定的宽度和“ float:left”,这种功能已经可以使用了。

My english is not the very best so pls take a look at my example picture first: 我的英语不是最好的,所以请先看一下我的示例图片:

这就是现在的样子!

As you can see there is this whitespace because of the third div which doesn't start right beneath the first div because of div number 2 which CAN BE higher as the first div. 如您所见,由于第三个div由于第2个div可能比第一个div高,所以第三个div不在第一个div下方,所以出现了空白。

I now wonder if there is a possibility to automatically position those divs higher so that there is no whitespace (they always should start right beneath the picture which is above wouth the whitespace, left or right). 我现在想知道是否有可能将这些div自动定位到更高的位置,从而没有空格(它们总是应该从图片的正下方开始,而图片位于空白的上方,向左或向右)。

LIKE THIS: 像这样:

它应该看起来像这样!

I hope you kinda understand what I mean :D Thanks in advance for replys! 希望您能理解我的意思:D预先感谢您的答复!

EDIT: Code-Example: 编辑:代码示例:

<div id="content">
<div class="xyz">BLABLA</div>
<div class="xyz">BLABLA<br>morebla!<br>EVEN MORE BLA</div>
<div class="xyz">BLABLA</div>
</div>
<style>
#content {
width: 648px;
}
.xyz {
width: 303px;
float: left;
border:1px solid black;
}
</style>

Remeber, heights are always different! 记住,身高总是不同的!

jQuery 砌体使您的生活变得更加轻松..不要重新发明轮子,尤其是当您面对经典的CSS问题时。

this will do it... 这会做到的...

   <div id="content">
    <div class="column1" id="left">
     <div id="div1">...</div>
     <div id="div3">...</div>
    </div>
    <div class="column2" id="left">
     <div id="div2">...</div>
     <div id="div4">...</div>
    </div>
   </div>

Then just style column2 styles by defining widht values in your css. 然后通过在CSS中定义Widht值来设置column2样式的样式。

Thanks, 谢谢,

@leo. @leo。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM