How can I justify masonry grid items to centre?
It seems that Masonry floats all my grid items to left or justifies the content to left:
<div class="wrap">
<div class="parent grid">
<div class="grid-item"><div>1</div></div>
<div class="grid-item"><div>2</div></div>
<div class="grid-item"><div>3</div></div>
<div class="grid-item"><div>4</div></div>
<div class="grid-item"><div>5</div></div>
</div>
</div>
CSS:
* {
box-sizing: border-box;
font-family: Arial, Sans-serif;
}
.wrap {
background: #FFD54F;
text-align: center;
}
.parent {
text-align: center;
width: 600px;
display: inline-block;
border: 1px solid black;
}
.parent > div {
width: 200px;
height: 100px;
background: white;
margin:5px;
padding:20px;
display: inline-block;
}
.parent > div > div {
font: bold 30px Arial, Sans-serif;
color: white;
width: 50px;
height: 50px;
background: #FAB400;
border-radius: 50%;
padding: 9px;
text-align:center;
}
What I am trying to achieve is this:
Is it possible?
You can just add another container to
.parent
and set its width just exactly the size of child elements including the margins and display it on the center. check this out:Sample