Skip to content Skip to sidebar Skip to footer

Css Float Elements With Unequal Heights Left And Up In Grid

I'm wondering how I can accomplish the effect in figure 1. What I have got so far is .box { display: inline-block; vertical-align: top; width: 100px;} This gives me the result

Solution 1:

You can use the popular library Masonry.

A dynamic layout plugin for jQuery The flip-side of CSS floats

Here is a code example...

$('#container').masonry({
  itemSelector: '.box'
});

Here is the source on Github and an interview with David Desandro on the Shoptalk podcast.

For folks that aren't using jQuery, note that there's also Vanilla Masonry which is the framework-free version.

Tip: Make sure the parent container has position:relative so all the content is bound to your container.

Solution 2:

Since you are already using jquery, jquery masonry might interest you: http://masonry.desandro.com

Solution 3:

Well, if you only aim to support the most modern browser, the CSS3 multi-column layout could help. One problem with this approach is that it will not keep the same order, but you can play with the order in the HTML (or Javascript).

I added a container around your spans called #container.

#container { 
    -webkit-column-width: 100px; 
    -moz-column-width: 100px; 
    column-width: 100px; 
}

jsFiddle Demo

Post a Comment for "Css Float Elements With Unequal Heights Left And Up In Grid"