I have some (unknown height) elements that adjust themselves horizontally with float: left;, but if one of those elements is taller, there is a space over the one in the next row. I'd like to move that element to the empty space over it. Here's a picture of the problem:
Is it possible to do this without JavaScript? Either way, how can I do this?
2 Answers
In CSS without JS:
you could have "Fotos" vertically aligned relative to "Contato" with
display: inline-block(whitespace is a bit annoying and there's an equivalent for IE6/7 if needed)you could have blocks of equal heights on each "line" either with faux-columns or CSS table layout (unrelated to unsemantic HTML table layout with
table,trandtdelements. Here it's layout with the elements of your choice)if you want to stack as much blocks as possible, then you'll have to create 2 columns, float them and stuff them with your blocks. This would change their order in your HTML code as they'd be written from top to bottom and then left to right ("Fotos" would come right after "Home" in the HTML code)
Comments
Just use javascript! jquery masonry was made for this!
clear: left;or right maybe it will be enough for now.