I have a set of rectangles of different sizes, and I want to put them next to each other so that there are as few spaces as possible: 
but for:
<div class="box" > <div class="item item-001" ></div> <div class="item item-003" ></div> <div class="item item-005" ></div> <div class="item item-002" ></div> <div class="item item-004" ></div> <div class="item item-001" ></div> <div class="item item-001" ></div> <div class="item item-003" ></div> <div class="item item-004" ></div> <div class="item item-001" ></div> </div>
and
div.box { width: 100%; height: 100%; display: block; border: 1px solid #EEE; padding: 3px; } div.item { display: inline-block; border: 1px solid orange; margin: 3px; width: 100px; } div.item-001 { height: 100px; } div.item-002 { height: 150px; } div.item-003 { height: 50px; } div.item-004 { height: 250px; } div.item-005 { height: 350px; }
here is what i get:

Is there any way to achieve this result with simple css? I want to avoid css3 and javascript, and I want the result to work in older browsers. If this is not possible, then I would like to know if this is possible with css3, and if not, then I will probably try javascript.
fiddle reference: http://jsfiddle.net/hamidsafdari/aa10xzzt/1/
javascript html css css3
hamid
source share