Stack divs with different heights

老子叫甜甜 提交于 2019-11-29 13:24:54

I suppose that you are using jQuery on your site. From the sketch I suggest to take a look at jQuery plugin called Masonry.

CSS:

.column { width:20em; float:left }
.column div { background:red; margin:1em }

HTML:

<div class="column">
    <div></div>
    <div></div>
    <div></div>
</div>
<div class="column">
    <div></div>
    <div></div>
    <div></div>
</div>
<div class="column">
    <div></div>
    <div></div>
    <div></div>
</div>

Have a look at using CSS Columns

Here's the W3C spec, but a slightly easier read might be PPK's write up.

Use three column divs within container div. Each floats left. Add a div at the top and at the bottom that's empty and clears on both sides.

.column { float: left; width: whatever you want it to be; margin-left: whatever you want it to be; }

.clear{ clear: both; height: 0px; }

.column div{ margin-bottom: whatever you want it to be; width: whatever you want it to be; }

       <div id='container'>

<div class='clear'>&nbsp;</div>

  <div class='column'>
<div>blah blah blah</div><div>blah blah blah</div>... etc
  </div>

  <div class='column'>
 <div>blah blah blah</div><div>blah blah blah</div>... etc
   </div>

  <div class='column'>
<div>blah blah blah</div><div>blah blah blah</div>... etc
  </div>

<div class='clear'>&nbsp;</div>

       </div>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!