Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center items inside isotope container?

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?

like image 430
Anfa A Avatar asked Nov 17 '14 03:11

Anfa A


2 Answers

Easiest way is to use masonry:

jsFiddle

var $container = $('#container');
// init
$container.isotope({
// options
itemSelector: '.box',
masonry: {
columnWidth: 40,
isFitWidth: true
}
});
like image 151
Macsupport Avatar answered Nov 04 '22 04:11

Macsupport


use masonry and add margin 0 auto to the grid.

js:

 masonry: {
  columnWidth: 100,
  fitWidth: true
}

css :

 .grid {
      margin: 0 auto;
  }
like image 44
achraf arrami Avatar answered Nov 04 '22 05:11

achraf arrami