How to center items inside isotope container?

Anfa A picture Anfa A · Nov 17, 2014 · Viewed 10.1k times · Source

I have an isotope grid with a non fixed width and I dont know how to center the items inside the isotope container.

.box{
width: 40px;
height: 40px;
background-color: #e74c3c;
margin: 0 auto;
}

that css fails to center the items. here is the link to the fiddle that illustrates my problem.

How can i make the red squares center inside the black box?

Answer

achraf arrami picture achraf arrami · Jul 30, 2020

use masonry and add margin 0 auto to the grid.

js:

 masonry: {
  columnWidth: 100,
  fitWidth: true
}

css :

 .grid {
      margin: 0 auto;
  }