<p class="notification">See also <a href="https://codepen.io/tutsplus/full/VwXjxMd" target="_blank">Responsive Image Grid With CSS Grid (Simple Example)</a></p>
<h1>Meet Morocco Through Beautiful <a href="https://unsplash.com/" target="_blank">Unsplash</a> Photos</h1>
<ul class="grid">
<!-- FIRST BUNCH OF IMAGES -->
<li style="--n: 0;">
<figure>
<img width="640" height="1138" src="https://assets.codepen.io/162656/morocco4.jpg" alt="">
</figure>
</li>
<li style="--n: 0;">
<figure>
<img width="640" height="427" src="https://assets.codepen.io/162656/morocco1.jpg" alt="">
</figure>
</li>
<li style="--n: 0;">
<figure>
<img width="640" height="427" src="https://assets.codepen.io/162656/morocco3.jpg" alt="">
</figure>
</li>
<li style="--n: 0;">
<figure>
<img width="640" height="427" src="https://assets.codepen.io/162656/morocco6.jpg" alt="">
</figure>
</li>
<li style="--n: 0;">
<figure>
<img width="640" height="418" src="https://assets.codepen.io/162656/morocco5.jpg" alt="">
</figure>
</li>
<li style="--n: 0;">
<figure>
<img width="640" height="853" src="https://assets.codepen.io/162656/morocco2.jpg" alt="">
</figure>
</li>
<li style="--n: 0;">
<figure>
<img width="640" height="314" src="https://assets.codepen.io/162656/morocco7.jpg" alt="">
</figure>
</li>
<li style="--n: 0;">
<figure>
<img width="640" height="427" src="https://assets.codepen.io/162656/morocco8.jpg" alt="">
</figure>
</li>
<li style="--n: 0;">
<figure>
<img width="640" height="960" src="https://assets.codepen.io/162656/morocco9.jpg" alt="">
</figure>
</li>
<li style="--n: 0;">
<figure>
<img width="640" height="427" src="https://assets.codepen.io/162656/morocco11.jpg" alt="">
</figure>
</li>
<li style="--n: 0;">
<figure>
<img width="640" height="427" src="https://assets.codepen.io/162656/morocco10.jpg" alt="">
</figure>
</li>
<!-- SECOND BUNCH OF IMAGES -->
<li style="--n: 1;">
<figure>
<img width="640" height="1141" src="https://assets.codepen.io/162656/morocco12.jpg" alt="">
</figure>
</li>
<li style="--n: 1;">
<figure>
<img width="640" height="853" src="https://assets.codepen.io/162656/morocco22.jpg" alt="">
</figure>
</li>
<li style="--n: 1;">
<figure>
<img width="640" height="648" src="https://assets.codepen.io/162656/morocco13.jpg" alt="">
</figure>
</li>
<li style="--n: 1;">
<figure>
<img width="640" height="480" src="https://assets.codepen.io/162656/morocco14.jpg" alt="">
</figure>
</li>
<li style="--n: 1;">
<figure>
<img width="640" height="427" src="https://assets.codepen.io/162656/morocco15.jpg" alt="">
</figure>
</li>
<li style="--n: 1;">
<figure>
<img width="640" height="962" src="https://assets.codepen.io/162656/morocco16.jpg" alt="">
</figure>
</li>
<li style="--n: 1;">
<figure>
<img width="640" height="427" src="https://assets.codepen.io/162656/morocco17.jpg" alt="">
</figure>
</li>
<li style="--n: 1;">
<figure>
<img width="640" height="425" src="https://assets.codepen.io/162656/morocco18.jpg" alt="">
</figure>
</li>
<li style="--n: 1;">
<figure>
<img width="640" height="853" src="https://assets.codepen.io/162656/morocco21.jpg" alt="">
</figure>
</li>
<li style="--n: 1;">
<figure>
<img width="640" height="427" src="https://assets.codepen.io/162656/morocco19.jpg" alt="">
</figure>
</li>
<li style="--n: 1;">
<figure>
<img width="640" height="426" src="https://assets.codepen.io/162656/morocco20.jpg" alt="">
</figure>
</li>
<!-- THIRD BUNCH OF IMAGES -->
<li style="--n: 2;">
<figure>
<img width="640" height="960" src="https://assets.codepen.io/162656/morocco30.jpg" alt="">
</figure>
</li>
<li style="--n: 2;">
<figure>
<img width="640" height="427" src="https://assets.codepen.io/162656/morocco23.jpg" alt="">
</figure>
</li>
<li style="--n: 2;">
<figure>
<img width="640" height="427" src="https://assets.codepen.io/162656/morocco25.jpg" alt="">
</figure>
</li>
<li style="--n: 2;">
<figure>
<img width="640" height="435" src="https://assets.codepen.io/162656/morocco26.jpg" alt="">
</figure>
</li>
<li style="--n: 2;">
<figure>
<img width="640" height="427" src="https://assets.codepen.io/162656/morocco28.jpg" alt="">
</figure>
</li>
<li style="--n: 2;">
<figure>
<img width="640" height="963" src="https://assets.codepen.io/162656/morocco24.jpg" alt="">
</figure>
</li>
<li style="--n: 2;">
<figure>
<img width="640" height="427" src="https://assets.codepen.io/162656/morocco29.jpg" alt="">
</figure>
</li>
<li style="--n: 2;">
<figure>
<img width="640" height="427" src="https://assets.codepen.io/162656/morocco32.jpg" alt="">
</figure>
</li>
<li style="--n: 2;">
<figure>
<img width="640" height="960" src="https://assets.codepen.io/162656/morocco27.jpg" alt="">
</figure>
</li>
<li style="--n: 2;">
<figure>
<img width="640" height="427" src="https://assets.codepen.io/162656/morocco31.jpg" alt="">
</figure>
</li>
<li style="--n: 2;">
<figure>
<img width="640" height="427" src="https://assets.codepen.io/162656/morocco33.jpg" alt="">
</figure>
</li>
</ul>
<footer class="page-footer">
<span>made by </span>
<a href="https://georgemartsoukos.com/" target="_blank">
<img width="24" height="24" src="https://assets.codepen.io/162656/george-martsoukos-small-logo.svg" alt="George Martsoukos logo">
</a>
</footer>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
margin: 80px 0 24px;
font-family: sans-serif;
}
a {
color: inherit;
}
.notification {
position: fixed;
top: 0;
left: 0;
right: 0;
padding: 10px;
text-align: center;
z-index: 1;
background: #fffbbc;
}
h1 {
text-align: center;
padding: 0 15px;
margin-bottom: 24px;
}
.grid {
display: grid;
grid-gap: 8px;
grid-template-columns: repeat(2, 1fr);
grid-auto-rows: 30vw;
list-style: none;
}
.grid li:nth-child(11n + 9) {
grid-column: 1 / -1;
grid-row: span 2;
}
.grid figure,
.grid img {
width: 100%;
height: 100%;
}
.grid img {
object-fit: cover;
background: #f5f3f4;
box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.2);
}
@media (min-width: 850px) {
.grid {
grid-gap: 24px;
grid-template-columns: repeat(5, 1fr);
grid-auto-rows: 12vw;
}
.grid li {
--row-step: calc(4 * var(--n));
}
.grid li:nth-child(11n + 1) {
grid-column: 1;
grid-row: calc(1 + var(--row-step)) / span 2;
}
.grid li:nth-child(11n + 2) {
grid-column: 2 / span 2;
grid-row: calc(1 + var(--row-step)) / span 2;
}
.grid li:nth-child(11n + 3) {
grid-column: 4;
grid-row: calc(1 + var(--row-step));
}
.grid li:nth-child(11n + 4) {
grid-column: 5;
grid-row: calc(1 + var(--row-step));
}
.grid li:nth-child(11n + 5) {
grid-column: 4;
grid-row: calc(2 + var(--row-step));
}
.grid li:nth-child(11n + 6) {
grid-column: 5;
grid-row: calc(2 + var(--row-step)) / span 2;
}
.grid li:nth-child(11n + 7) {
grid-column: 2;
grid-row: calc(3 + var(--row-step));
}
.grid li:nth-child(11n + 8) {
grid-column: 1;
grid-row: calc(3 + var(--row-step));
}
.grid li:nth-child(11n + 9) {
grid-column: 3 / span 2;
grid-row: calc(3 + var(--row-step)) / span 2;
}
.grid li:nth-child(11n + 10) {
grid-column: 1 / span 2;
grid-row: calc(4 + var(--row-step));
}
.grid li:nth-child(11n + 11) {
grid-column: 5;
grid-row: calc(4 + var(--row-step));
}
}
/* FOOTER STYLES
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.page-footer {
position: fixed;
right: 0;
bottom: 50px;
display: flex;
align-items: center;
padding: 5px;
z-index: 1;
color: black;
background: white;
}
.page-footer a {
display: flex;
margin-left: 4px;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.