I'm currently designing an image collage for my website and attempted to use masonry for the layout. However, when I adjust the size of the blocks, they seem to drift apart, creating large gaps between each block. Any suggestions on how to resolve this issue?
* {
box-sizing: border-box;
}
body {
font-family: sans-serif;
}
/* ---- grid ---- */
.grid {
border: 5px solid black;
overflow: hidden;
background: #EEE;
max-width: 1346px;
max-height: 400px;
}
/* clearfix */
.grid:after {
content: '';
display: block;
clear: both;
}
/* ---- grid-item ---- */
.grid-item {
width: 240px;
height: 180px;
background: #D26;
border: 2px solid #333;
border-color: hsla(0, 0%, 0%, 0.5);
border-radius: 5px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8>
<title>Masonry - Initialize in HTML</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<h1>Masonry - Initialize in HTML</h1>
<div class="grid" data-masonry='{ "itemSelector": ".grid-item", "columnWidth": 160 }'>
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
<div class="grid-item"></div>
</div>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://masonry.desandro.com/masonry.pkgd.js'></script>
<script src="js/index.js"></script>
</body>
</html>
If it's not visible here, you'll need to create a file for it to understand what's happening. https://i.sstatic.net/JyLoj.png
Thank you!