Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Masonry-style Layout ONLY with CSS

Tags:

html

css

As you can see in the image every box has a different height and there are some boxes with double width.

Layout

Is it possible to create a masonry-style layout only with CSS?

like image 266
Bernat Avatar asked Aug 24 '12 22:08

Bernat


People also ask

How do you make a masonry layout with CSS grid?

To use masonry layout, one of your grid axes needs to have the value masonry . This will then be referred to as the masonry axis, the other axis will have rows or column tracks defined as normal, this will be the grid axis. The CSS below creates a four-column grid, with the rows set to masonry .

What is a masonry layout?

Masonry layout is a layout method where one axis uses a typical strict grid layout, most often columns, and the other a masonry layout. On the masonry axis, rather than sticking to a strict grid with gaps being left after shorter items, the items in the following row rise up to completely fill the gaps.

What is mosaic layout?

A mosaic divides a map layout up into multiple pages in a PDF. It is designed for printing large layouts on a smaller sheet size and combing back together. This tool is similar to poster printing utilities available in other applications.


1 Answers

With css3 support you could do this:

http://jsfiddle.net/huAxS/2/

.container {
    -moz-column-count: 2;
    -moz-column-gap: 10px;
    -webkit-column-count: 2;
    -webkit-column-gap: 10px;
    column-count: 2;
    column-gap: 10px;
    width: 360px;
}

.container div {
    display: inline-block;
    width: 100%;
    background-color: red;
}​

With no css3 support, you have to resort to js unfortunately.

like image 108
Esailija Avatar answered Oct 22 '22 06:10

Esailija