While stacking DIVs of varying height, it creates a lot of empty space while it breaks to the next line. Group 1 and Group 5 in the attached image. I tried inline-block, float:left, display: flex;flex-wrap: wrap; and few other properties and cant seem to figure this out. I see other posts recommending JQuery based solutions. Is it possible to achieve this using HTML and CSS only [pinterest style layout]?
<html>
<head>
<style>
body { background: none repeat scroll 0 0 #EFEFEF; font-size:12px;font-family: "Courier New", "Courier", "monospace"; }
fieldset{border-color: grey;border-style: solid;}
div.groups{ width:300px;float:left;padding:5px 3px 5px 8px;}
div.container{ width:100%;}
</style>
</head>
<body><br>
<div class = "container">
<div class = "groups"><fieldset> <legend><b>Group 1</b></legend>
<ol><li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li>
</ol></fieldset></div>
<div class = "groups"><fieldset> <legend><b>Group 2</b></legend><ol><li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li>
</ol></fieldset></div>
<div class = "groups"><fieldset> <legend><b>Group 3</b></legend><ol><li></li> <li></li> <li></li> <li></li> <li></li> <li></li>
</ol></fieldset></div>
<div class = "groups"><fieldset> <legend><b>Group 4</b></legend><ol><li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li>
</ol></fieldset></div>
<div class = "groups"><fieldset> <legend><b>Group 5</b></legend><ol><li></li> <li></li>
</ol></fieldset></div>
<div class = "groups"><fieldset> <legend><b>Group 6</b></legend><ol><li></li> <li></li> <li></li> <li></li> <li></li> <li></li>
</ol></fieldset></div>
<div class = "groups"><fieldset> <legend><b>Group 7</b></legend><ol><li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li>
</ol></fieldset></div>
</div>
</body>
</html>