I'm trying to create an image gallery with Flexbox, Something similar to the one on AirBnb website. The gallery consists of 5 images. The first image takes 50% of the width of the container and 100% of it height. The rest of the images (4) takes 25% width of the container each, and 50% height.
I tried using the code below, but I couldnt get image 4 and 5 to align right under image 2 and 3. and to the side of image 1.
I need help to make this work. My current code is below
.container {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
margin: 0 auto;
}
.row {
width: 100%;
height: 100%;
max-width: 1000px;
margin: 10px 0;
display: flex;
flex-wrap: wrap;
}
.img-1 {
background: url("https://images.unsplash.com/photo-1422205512921-12dac7b3b603?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2255&q=80")
no-repeat center center;
background-size: cover;
width: 100%;
}
.img-2 {
background: url("https://images.unsplash.com/photo-1528696892704-5e1122852276?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2250&q=80")
no-repeat center center;
background-size: cover;
width: 100%;
}
.img-3 {
background: url("https://images.unsplash.com/photo-1524678606370-a47ad25cb82a?ixlib=rb-1.2.1&auto=format&fit=crop&w=2250&q=80")
no-repeat center center;
background-size: cover;
width: 100%;
}
.img-4 {
background: url("https://images.unsplash.com/photo-1563305145-b64e0c2184aa?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2250&q=80")
no-repeat center center;
background-size: cover;
width: 100%;
}
.img-5 {
background: url("https://images.unsplash.com/photo-1559136555-9303baea8ebd?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2250&q=80")
no-repeat center center;
background-size: cover;
width: 100%;
}
.row {
height: 600px;
}
.img-1 {
height: 100%;
width: 50%;
}
.img-2,
.img-3,
.img-4,
.img-5 {
width: 25%;
height: 50%;
}
<div class="container">
<div class="row">
<div class="img-1"></div>
<div class="img img-2"></div>
<div class="img img-3"></div>
<div class="img img-4"></div>
<div class="img img-5"></div>
</div>
</div>