11

I want to stack divs with different heights but same width within a div container.. from top to bottom going right.

Problem now is with divs that are short.. gives a ugly gap to the div above.

I've added a small sketch with what i want to do.. enter image description here

Thanks from norway!

user681061
  • 255
  • 5
  • 16

4 Answers4

2

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

Bakudan
  • 19,134
  • 9
  • 53
  • 73
  • Bakudan: I can just say WOW! This is the stuff i've been looking for! Perfect, specially the image solution at http://masonry.desandro.com/demos/images.html. Big thanks! This is why i love stackoverflow :) Beautiful solutions. – user681061 May 26 '11 at 13:11
1

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>
Midas
  • 7,012
  • 5
  • 34
  • 52
0

Have a look at using CSS Columns

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

nickf
  • 537,072
  • 198
  • 649
  • 721
0

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>
AR.
  • 1,935
  • 1
  • 11
  • 14