You can set the width of the wrapper and place those blocks that are 100 pixels tall in it.
Here is an example: http://jsfiddle.net/BVm5h/
the code:
<div class="wrapper"> <div class="myClass">1</div> <div class="myClass">2</div> <div class="myClass">3</div> <div class="myClass">4</div> <div class="myClass">5</div> <div class="myClass">6</div> <div class="myClass">7</div> <div class="myClass">8</div> <div class="myClass">9</div> <div class="myClass">10</div> </div>
CSS
.wrapper {width: 600px;} .myClass { border-top: 1px solid #FF0000; border-bottom: 1px solid #FF0000; width: 100px; height: 100px; float:left; margin-top: 5px; } div.myClass:last-child { width: 100%; }β
JS:
var no = $('div.myClass').length; var wlength = $('div.wrapper').width(); var length = $('div.myClass').width(); var tno = no*length; while(wlength < tno) tno=tno-wlength; var mw = wlength+length-tno; $('div.myClass').last().css('max-width',mw);
By changing the width of the wrapper, you can set the number of div blocks that you want in each row.
Edit: Added JS if the last item needs to be expanded for the whole line.
Ankit source share