I have the following React snippet:
const CategoryItem = ({ imageUrl, title }) => {
return (
<div className='category-container'>
<div
className='category-container__bg'
style={{ backgroundImage: `url(${imageUrl})` }}
></div>
<div className='category-container__body'>
<h2>{title}</h2>
<p>Shop Now</p>
</div>
</div>
);
};
and styled as follows using Sass:
.category-container {
align-items: center;
border: 5px solid #000;
display: flex;
flex: 1 1 30%;
height: 25rem;
justify-content: center;
margin: 10px;
overflow: hidden;
&__bg {
background-position: center;
background-size: cover;
background-repeat: no-repeat;
height: 100%;
transition: transform 1.5s ease;
width: 100%;
}
&__body {
align-items: center;
background-color: white;
border: 3px solid black;
display: flex;
flex-direction: column;
height: 7rem;
justify-content: center;
opacity: 0.7;
padding: 0 1.5625rem;
position: absolute;
transition: opacity 1s ease;
h2 {
color: #4a4a4a;
font-size: 1.375rem;
font-weight: bold;
margin: 0 0.375rem 0;
}
p {
font-size: 1rem;
font-weight: lighter;
}
}
&:hover {
cursor: pointer;
.category-container__bg {
transform: scale(1.05);
}
.category-container__body {
opacity: 0.9;
}
}
}
Although I am using background-size: cover, I am getting a weird whitespace around the background image (shown in the screenshot below). I have tried playing with the border as this sometimes fixes the issue, but it is not working for this case.
Are there any workarounds for this issue?
