1

我想从这里互锁未定义数量的 div(如在 Pinterest 中):

++++++++ ********
+      + *      *
+      + *      *
+      + ********
+      +         
++++++++ 
~~~~~~~~ --------
~      ~ -      -
~      ~ -      -
~~~~~~~~ -      -
         -      -
         -      -
         -      -
         -      -
         --------

对此:

++++++++ ********
+      + *      *
+      + *      *
+      + ********
+      + --------
++++++++ -      -
~~~~~~~~ -      -
~      ~ -      -
~      ~ -      -
~~~~~~~~ -      -
         -      -
         -      -
         --------

CSS或其他东西有可能吗?

4

2 回答 2

3

这已经被问了一百万次了。

大多数人使用砌体:

http://masonry.desandro.com/

于 2013-02-07T10:12:01.823 回答
1

感谢zessx ,我从zessx的答案中引用了这个答案。

<h2>Without columns</h2>
<div class="box">1 Lorem Ipsum</div>
<div class="box">2 Lorem Ipsum Lorem Ipsum</div>
<div class="box">3 Lorem Ipsum</div>
<p class="clear">&nbsp;</p>
<div class="box">4 Lorem Ipsum Lorem</div>
<div class="box">5 Lorem Ipsum</div>
<div class="box">6 Lorem Ipsum</div>
<p class="clear">&nbsp;</p>
<div class="box">7 Lorem Ipsum</div>
<div class="box">8 Lorem Ipsum</div>
<h2>With columns</h2>
<div class="column">
<div class="box">1 Lorem Ipsum</div>
<div class="box">4 Lorem Ipsum Lorem</div>
<div class="box">7 Lorem Ipsum</div>
</div>
<div class="column">
<div class="box">2 Lorem Ipsum Lorem Ipsum</div>
<div class="box">5 Lorem Ipsum</div>
<div class="box">8 Lorem Ipsum</div>
</div>
<div class="column">
<div class="box">3 Lorem Ipsum</div>
<div class="box">6 Lorem Ipsum</div>
</div>

CSS

.box { 
width: 50px;
min-height: 50px;
background: #ccc;
margin: 3px;
padding: 3px;
float: left;
}
.clear {
clear: both;
height: 0px;
}
.column {
width:60px;
float: left;
}

看演示

于 2013-02-07T10:32:37.520 回答