Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get different height html divs to float up

Tags:

html

css

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>

flow.jpg

When I "float: left" the divs wrap as expected leaving white space between the shorter divs and the next row of divs.

flow2.jpg

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

enter image description here

like image 725
DanielEli Avatar asked Sep 19 '11 01:09

DanielEli


People also ask

How do you make two divs float the same height?

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.

How do I change the dynamic height in HTML?

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.

How do you make the height of two divs equal?

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.


Video Answer


1 Answers

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/

like image 194
brenjt Avatar answered Sep 23 '22 18:09

brenjt