I have spent countless hours trying to figure out how to properly turn this section into a grid layout of a total of 5 images the 1st image on top left 4th image bottom left 2nd image in the middle top and bottom and the 3rd image top right and 5th image bottom right. I’ll include pictures of what I have tried and how it looks. I have tried using regular CSS as well as doing it with Tailwind classes and after a lot of research online and watching videos I haven’t been able to crack it. I got close but it isn’t how I want it to look. Any help will be greatly appreciated.
/* .topNotchImg {
width: 50%;
height: 300px;
} */
.gridTopNotch {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr 1fr;
gap: 5px 5px;
padding: 30px;
grid-template-areas: "pic-1 pic-1 pic-2 pic-2 pic-3 pic-3" "pic-1 pic-1 pic-2 pic-2 pic-3 pic-3" "pic-4 pic-4 pic-2 pic-2 pic-5 pic-5" "pic-4 pic-4 pic-2 pic-2 pic-5 pic-5";
}
.pic-1 {
grid-area: pic-1;
}
.pic-2 {
grid-area: pic-2;
}
.pic-3 {
grid-area: pic-3;
}
.pic-4 {
grid-area: pic-4;
}
.pic-5 {
grid-area: pic-5;
}
<section>
<div class="text-center">
<h1 class="text-5xl pb-2"><strong>Top Notch Destinations</strong></h1>
<p>These places are on everyone's bucket list</p>
</div>
<div class="gridTopNotch">
<div class="topNotchImg pic-1">
<img src="img/destinations-machu.jpg" alt="Machu Picchu" />
<h4 class="text-xl"><strong>Machu Picchu</strong></h4>
<p>Peru</p>
</div>
<div class="topNotchImg pic-2">
<img src="img/destinations-rome.jpg" alt="Rome" />
<h4 class="text-xl"><strong>Rome</strong></h4>
<p>Italy</p>
</div>
<div class="topNotchImg pic-3">
<img src="img/destinations-sydney.jpg" alt="Sydney" />
<h4 class="text-xl"><strong>Sydney</strong></h4>
<p>Australia</p>
</div>
<div class="topNotchImg pic-4">
<img src="img/destinations-paris.jpg" alt="Paris" />
<h4 class="text-xl"><strong>Paris</strong></h4>
<p>France</p>
</div>
<div class="topNotchImg pic-5">
<img src="img/destinations-rio.jpg" alt="Rio de Janeiro" />
<h4 class="text-xl"><strong>Rio de Janeiro</strong></h4>
<p>Brazil</p>
</div>
</div>
</section>
With Tailwind:
<script src="https://cdn.tailwindcss.com"></script>
<div class="grid grid-cols-2 grid-flow-row gap-4">
<img
src="img/destinations-machu.jpg"
alt="Image 1"
class="rounded-md shadow-lg h-auto w-auto"
/>
<img
src="img/destinations-rome.jpg"
alt="Image 2"
class="rounded-md shadow-lg h-auto w-auto"
/>
<img
src="img/destinations-sydney.jpg"
alt="Image 3"
class="rounded-md shadow-lg h-auto w-auto"
/>
<img
src="img/destinations-paris.jpg"
alt="Image 4"
class="rounded-md shadow-lg h-auto w-auto"
/>
<img
src="img/destinations-rio.jpg"
alt="Image 5"
class="rounded-md shadow-lg h-auto w-auto"
/>
</div>
This is the Link for How it looks with the HTML and CSS
This is the Link for How it looks with Tailwind
This is How I am Trying to get it to look
I want to say thank you in advance – I’m not sure what else to do and I can’t seem to figure it out.
2
Answers
Consider simplifying it down to the required grid areas. You are going to want 3 columns, with the middle element spanning two rows.
One approach is as follows, with explanatory comments in the code:
JS Fiddle demo.
References:
::after
.block-size
.box-sizing
.content
.display
.flex-direction
.gap
.grid-area
.grid-template-areas
.grid-template-columns
.max-inline-size
.object-fit
.padding
.padding-block
.padding-inline
.