My current code includes an overlay over images, but the overlay extends beyond the image itself and covers the padding area as well. If I switch the padding to margin in order to eliminate this unnecessary overlap, it causes the last image to be pushed onto a new row.
.sb-overlay{
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #0a0a0a;
z-index: 2;
cursor: pointer;
opacity: 0;
transition: all 0.5s;
-webkit-transition: all 0.5s;
}
.sb-overlay:hover{
opacity: 0.5;
}
.sb-text{
color: #ffffff;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
font-size: 18px;
font-weight: bold;
}
.s-image img{
width: 100%
}
.grid-item{
padding:5px !important;
}
<script
src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js"></script>
<div class="row">
<div class="grid-item col-sm-6 col-md-4">
<a data-content="Here is a caption" class="magnific-popup s-image" href="https://picsum.photos/600/300">
<img title="This is the title" src="https://picsum.photos/600/300" />
<div class="sb-overlay">
<div class="sb-text">
This is the title
</div>
</div>
</a>
</div>
[Insert remaining grid items here]
</div>
I'm looking for a solution to remove the overlay from the padding area and make it the exact size of the image. Any advice on how to achieve this?