<h3>Grid items are set in percentage units</h3>
<div class="container" style="--columns: repeat(4, 25%)">
<figure>
<img src="https://picsum.photos/300/300?random=1" alt="">
</figure>
<figure>
<img src="https://picsum.photos/300/300?random=2" alt="">
</figure>
<figure>
<img src="https://picsum.photos/300/300?random=3" alt="">
</figure>
<figure>
<img src="https://picsum.photos/300/300?random=4" alt="">
</figure>
</div>
<h3>Grid items are set in percentage units</h3>
<div class="container" style="--columns: repeat(4, calc(100% - 3 * 1rem) / 4))">
<figure>
<img src="https://picsum.photos/300/300?random=1" alt="">
</figure>
<figure>
<img src="https://picsum.photos/300/300?random=2" alt="">
</figure>
<figure>
<img src="https://picsum.photos/300/300?random=3" alt="">
</figure>
<figure>
<img src="https://picsum.photos/300/300?random=4" alt="">
</figure>
</div>
<h3>Grid items are set in percentage units</h3>
<div class="container" style="--columns: repeat(4, calc(100% - 3 * 1rem) / 4))">
<figure>
<img src="https://picsum.photos/300/300?random=1" alt="">
</figure>
<figure>
<img src="https://picsum.photos/300/300?random=2" alt="">
</figure>
<figure>
<img src="https://picsum.photos/300/300?random=3" alt="">
</figure>
<figure>
<img src="https://picsum.photos/300/300?random=4" alt="">
</figure>
</div>
<h3>Grid items are set in fraction units</h3>
<div class="container" style="--columns: repeat(4, 1fr)">
<figure>
<img src="https://picsum.photos/300/300?random=5" alt="">
</figure>
<figure>
<img src="https://picsum.photos/300/300?random=6" alt="">
</figure>
<figure>
<img src="https://picsum.photos/300/300?random=7" alt="">
</figure>
<figure>
<img src="https://picsum.photos/300/300?random=8" alt="">
</figure>
</div>
<h3>Grid items are set in fraction units</h3>
<div class="container" style="--columns: repeat(4, 25fr)">
<figure>
<img src="https://picsum.photos/300/300?random=5" alt="">
</figure>
<figure>
<img src="https://picsum.photos/300/300?random=6" alt="">
</figure>
<figure>
<img src="https://picsum.photos/300/300?random=7" alt="">
</figure>
<figure>
<img src="https://picsum.photos/300/300?random=8" alt="">
</figure>
</div>
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 100vw;
min-height: 100vh;
font-family: "Exo", Arial, sans-serif;
background-color: #557;
color: #fff;
display: grid;
grid-template-columns: 1fr min(100% - 10px, 700px) 1fr;
gap: 1rem;
align-items: start;
align-content: start;
}
body > * {
grid-column: 2 / 3;
}
figure {
aspect-ratio: 1 / 1;
border-radius: 6px;
border: 1px solid rgb(0 0 0 / 0.125);
box-shadow: 0 0 1px 1px rgb(0 0 0 / 0.025);
overflow: hidden;
margin: 0;
padding: 0;
}
figure img {
height: 100%;
width: 100%;
object-fit: cover;
}
.container {
padding: 1rem;
border: 1px dashed #09face;
border-radius: 6px;
display: grid;
gap: 1rem;
grid-template-columns: var(--columns, repeat(4, 1fr));
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.