https://i.sstatic.net/KwOJh.jpg When stacking DIVs with varying heights, a lot of empty space is created when they break to the next line, as shown in Group 1 and Group 5 in the image. I've tried using inline-block, float:left, display: flex;flex-wrap: wrap; and some other properties but can't seem to figure this out. I've seen other posts recommending JQuery-based solutions. Is it possible to achieve a Pinterest-style layout using only HTML and CSS?
<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>