I am facing an issue with my containers, specifically .grid.left
and .grid.right
. The images within each of these grids are dynamic and enclosed within another div called .gallery
.
The problem arises when I apply margins to the image boxes, causing gaps within the .gallery
like this:
https://i.sstatic.net/UbHPt.jpg
My goal is to eliminate these gaps in the .gallery
and ensure that the images fit perfectly regardless of the margin settings.
I had intended to apply margins for a better appearance in the gallery. I would like to retain these margins and only expand the .grid.right
image to fit between the image and the .outer
div.
Is there a proper solution to address this issue?
Snippets:
* {
margin: 0;
padding: 0;
}
div,
section {
position: relative;
}
.gallery {
width: 1200px;
height: 100%;
border: 1px solid black;
box-sizing: border-box;
}
.article {
width: 100%;
height: 100%;
display: flex;
flex-flow: row;
align-items: center;
}
.grid {
height: 100%;
}
.left {
width: 60%;
}
.inset-contents {
width: 100%;
height: 50%;
}
.top {
margin-bottom: 1rem;
background-image: url('https://imgur.com/3ozQvk9.jpg');
padding-bottom: 50%;
}
.bottom {
display: flex;
flex-flow: row;
}
.inner-contents {
width: 50%;
}
.first {
background-image: url('https://imgur.com/tOMRVDi.jpg');
padding-bottom: 50%;
margin-right: .5rem;
}
.second {
background-image: url('https://imgur.com/4oewNdx.jpg');
padding-bottom: 50%;
margin-left: .5rem;
}
.right {
width: 40%;
background-image: url('https://imgur.com/7gB1jHR.jpg');
padding-bottom: 60%;
align-content: stretch;
margin-left: 1rem;
}
.img {
display: block;
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
}
<div class="gallery">
<div class="article">
<div class="grid left">
<a class="inset-contents top img"></a>
<div class="inset-contents bottom">
<a class="inner-contents first img"></a>
<a class="inner-contents second img"></a>
</div>
</div>
<a class="grid right img"></a>
</div>
</div>