As the title suggests, I wanted to add a background both to the image and the div itself. I see it's being used on amazon but can't seem to figure out the trick behind it. What I mean is, the image has a white background, but the image as it's been applied onto the div doesn't show that white space. Like so:
Image with white background:
Image being rendered onto the div:
Here is what I have tried so far:
.grid-wrapper {
display: grid;
grid-template-columns: 1fr 2fr;
background: #fff;
box-shadow: rgba(0, 0, 0, 0.02) 0px 1px 3px 0px, rgba(27, 31, 35, 0.15) 0px 0px 0px 1px;
border-radius: 4px;
}
.image-block {
background: red;
margin: auto;
}
.image-block img {
width: 100%
height: 100%;
}
.information {
padding: 10px;
}
.information p {
font-size: 0.875rem;
line-height: 1.5;
}
<div class="grid-wrapper">
<div class="image-block">
<img src="https://m.media-amazon.com/images/I/61xgpXecLML._AC_UY218_.jpg">
</div>
<div class="information">
<p>Logitech M510 Wireless Computer Mouse for PC with USB Unifying Receiver - Graphite</p>
<p>Price: $100</p>
</div>
</div>
You can see a bit of the background: red;
just under the image.