I am trying to figure out how I can get a flex layout (or some other layout if flex is not the way to go) that will allow the WIDGET 4 and 6 in my example to float up underneath WIDGETS 1 and 3. Because WIDGET 2 is larger, it pushes the rest of them down to it's height. The solution needs to be flexible to allow for more WIDGET divs that would cause similar issues with content below them. I want all the WIDGETS to float up underneath the row above.
as a side note - all of my WIDGET divs are sortable using the jQuery UI sortable plugin - so the solution must allow them to "snap" into place after the sort as well.
How can I accomplish this?
#widgetWrapper {
padding:10px 15px;
position:relative;
display:flex;
flex-wrap:wrap;
flex-direction:row;
}
.widget {
width:33.3%;
box-sizing:border-box;
padding:10px 20px 10px 10px;
position:relative;
}
<div id="widgetWrapper">
<div class="widget">
<p><strong>WIDGET 1</strong></p>
CONTENT<br />CONTENT<br />CONTENT<br />CONTENT<br />
</div>
<div class="widget">
<p><strong>WIDGET 2</strong></p>
CONTENT<br />CONTENT<br />CONTENT<br />CONTENT<br />
CONTENT<br />CONTENT<br />CONTENT<br />CONTENT<br />
</div>
<div class="widget">
<p><strong>WIDGET 3</strong></p>
CONTENT<br />CONTENT<br />CONTENT<br />CONTENT<br />
</div>
<div class="widget">
<p><strong>WIDGET 4</strong></p>
CONTENT<br />CONTENT<br />CONTENT<br />CONTENT<br />
</div>
<div class="widget">
<p><strong>WIDGET 5</strong></p>
CONTENT<br />CONTENT<br />CONTENT<br />CONTENT<br />
</div>
<div class="widget">
<p><strong>WIDGET 6</strong></p>
CONTENT<br />CONTENT<br />CONTENT<br />CONTENT<br />
</div>
</div>