I'm working on a React project where I have a set of cards, each with a dynamic background image loaded from a JSON file. My goal is to create a hover effect on these cards, where the background image darkens, and the title and a small description appear. I've managed to make the title and description appear using opacity transitions, but I'm facing a challenge with darkening the background image because I can't directly apply a linear gradient to it using CSS. I'm looking for a simple and efficient solution to achieve this effect without making the code too complex.
Current Code: Here's the current code structure I have for the card component:
const Card = ({ card }) => {
return (
<div className="home__prom-card" style={{ backgroundImage: `url(${card.image})` }}>
<div className="home__prom-card_price">
<h3>{card.price}</h3>
</div>
<h2>{card.name}</h2>
<p>{card.description}</p>
</div>
);
};
I've encountered difficulties in applying a darkened overlay on the background image when hovering over the card. Since the background image is loaded dynamically from a JSON file, I can't directly apply a linear gradient overlay using CSS.