I've got a series of dynamically created divs of varying heights in a container div.
<div id="container">
<div id='d1'>Varying text...</div>
<div id='d2'>Varying text...</div>
<div id='d3'>Varying text...</div>
<div id='d4'>Varying text...</div>
<div id='d5'>Varying text...</div>
<div id='d6'>Varying text...</div>
<div id='d7'>Varying text...</div>
</div>
When I "float: left" the divs wrap as expected leaving white space between the shorter divs and the next row of divs.
How would I get the divs to effectively "float: up", wrapping veritcally rather than horizonatally. Using only css.
Ideally, item 2 would be under item 1 but any improvement would help.
So it would end up looking like this
Answer: Use the CSS3 flexbox With CSS3 flex layout model you can very easily create the equal height columns or <div> elements that are aligned side by side. Just apply the display property with the value flex on the container element and the flex property with the value 1 on child elements.
We use css property height: calc( 100% - div_height ); Here, Calc is a function. It uses mathematical expression by this property we can set the height content div area dynamically.
The two or more different div of same height can be put side-by-side using CSS. Use CSS property to set the height and width of div and use display property to place div in side-by-side format. The used display property are listed below: display:table; This property is used for elements (div) which behaves like table.
Try using jQuery Masonry. It could be a great fix for this.
http://masonry.desandro.com/
Or try Isotope, which has much better performance
http://isotope.metafizzy.co/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With