Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Better" floating in CSS

I'm experimenting with CSS and the float property. I have this "website", with a lot of divs aligned to 80px grid and float: left:

Simple CSS floating

Is there a way in CSS to make it looking like this - so the elements can use empty space above them?

More compact - uses empty space above the elements

Without JavaScript, if it's possible.

Thanks, Martin.

like image 466
Martin Majer Avatar asked Aug 13 '12 21:08

Martin Majer


People also ask

Is it good practice to use float in CSS?

Floats are an excellent way to position elements on your page, sometimes essential in fact. Show activity on this post. When using float, a box is first laid out according to the normal flow, then taken out of the flow and shifted to the left or right as far as possible.

Should I use float or Flex?

Using floats we are limited to place items left or right but using flexbox we can modify our models in all four directions. Flexbox is a new concept in CSS to achieve a responsive webpage with some important properties of flexbox. We should use flexbox over floats.

What are the disadvantages of float in CSS?

Floating everything can make for a great deal of inconsistency; depending on how wide a screen is and how tall certain elements are rendered, you can end up with a hodgepodge of screen jag. For example, widening the screen would cause more elements to fit on the top line, so they would jump up.


1 Answers

No, this can't be done in CSS. Best way is to use a javascript item called masonry I'm afraid.

http://masonry.desandro.com/

like image 125
Billy Moat Avatar answered Sep 17 '22 13:09

Billy Moat