I have a container image-wrapper
and an image inside it.
The container has a fixed height and width. Inside it, the image resolution will be dynamic.
All I am trying to do is to center the image to the container, horizontally and vertically and apply some box-shadow
styling to it.
But it leaves a blank space around the image, and it looks weird. Below is the code. It happens same with a vertical image.
.image-wrapper {
height: 400px;
width: 400px;
background-color: rgb(0,200,100);
padding: 40px;
}
.image-wrapper img {
width: 100%;
height: 100%;
object-fit: contain;
box-shadow: 10px 10px 10px red;
}
<div class="image-wrapper">
<img src="https://via.placeholder.com/500x200">
</div>
I want to have a shadow around the image only, without the spaces. I think I am missing a very simple thing here.
I have tried to add position: relative
to the container, but it didn't work.
I tried to search about it by searching something like "css object fit image shadow", "css object fit on image adds spaces" and didn't found anything similar to it.