masonry only css test
by hohoya33
HTML
<div class="masonry">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
</div>
<div class="container">
<div class="item" style="height: 140px"></div>
<div class="item" style="height: 190px"></div>
<div class="item" style="height: 170px"></div>
<div class="item" style="height: 120px"></div>
<div class="item" style="height: 160px"></div>
<div class="item" style="height: 180px"></div>
<div class="item" style="height: 140px"></div>
<div class="item" style="height: 150px"></div>
<div class="item" style="height: 170px"></div>
<div class="item" style="height: 170px"></div>
<div class="item" style="height: 140px"></div>
<div class="item" style="height: 190px"></div>
<div class="item" style="height: 170px"></div>
<div class="item" style="height: 120px"></div>
<div class="item" style="height: 160px"></div>
<div class="item" style="height: 180px"></div>
<div class="item" style="height: 140px"></div>
<div class="item" style="height: 150px"></div>
<div class="item" style="height: 170px"></div>
<div class="item" style="height: 170px"></div>
</div>
CSS
/* .masonry {
display: grid;
grid-gap: 1em;
grid: masonry / repeat(auto-fit, minmax(20em, 1fr));
}
*/
/* .masonry {
column-count: 4;
column-gap: 1em;
} */
.masonry{
display: grid;
grid-column-gap: 0px;
grid-row-gap: 0px;
grid-template-columns: repeat(auto-fill, minmax(315px,1fr));
grid-auto-rows: 25px;
}
item {
position: relative;
display: flex;
flex-direction: column;
min-width: 0;
word-wrap: break-word;
background-color: #fff;
background-clip: border-box;
border: 1px solid rgba(0, 0, 0, 0.125);
border-radius: 0.25rem;
}
/* item {
background-color: Gainsboro;
color: white;
page-break-inside: avoid;
break-inside: avoid;
margin: 1rem 0 1rem 0;
width: 100%;
height: 250px;
display: flex;
justify-content: center;
align-items: center;
} */
item:nth-child(1) {
margin-top: 0;
height: 300px;
}
item:nth-child(2) {
height: 200px;
}
item:nth-child(3) {
height: 150px;
}
item:nth-child(4) {
height: 200px;
}
item:nth-child(5) {
height: 400px;
}
item:nth-child(6) {
margin-bottom: 0;
}
.container {
display: flex;
flex-flow: column wrap;
align-content: space-between;
/* Your container needs a fixed height, and it
* needs to be taller than your tallest column. */
height: 960px;
/* Optional */
background-color: #f7f7f7;
border-radius: 3px;
padding: 20px;
margin: 40px auto;
counter-reset: items;
}
.item {
width: 50%;
/* Optional */
position: relative;
margin-bottom: 2%;
border-radius: 3px;
background-color: #a1cbfa;
border: 1px solid #4290e2;
box-shadow: 0 2px 2px rgba(0,90,250,0.05),
0 4px 4px rgba(0,90,250,0.05),
0 8px 8px rgba(0,90,250,0.05),
0 16px 16px rgba(0,90,250,0.05);
color: #fff;
padding: 15px;
box-sizing: border-box;
}
/* Just to print out numbers */
div.item::before {
counter-increment: items;
content: counter(items);
}
/* Re-order items into 3 rows */
.item:nth-of-type(4n+1) { order: 1; }
.item:nth-of-type(4n+2)...