How do I properly set a background image in a .css file located in the src folder?
src/Components/Component/Comp.css
.services {
background-image : url("./images/img-2.jpg");
background-position: center;
background-size : cover;
background-repeat : no-repeat;
color : #fff;
font-size : 100px;
}
After encountering an error:
Error: ENOENT: no such file or directory, open 'C:\xampp\htdocs\react\react-website\src\images\img-1.jpg'
To fix it, I transferred the images folder from public to src, which resolved the issue. However, now I am facing difficulty accessing those images in a React Component, such as:
src/Components/Cards/Cards.js
<CardItem
src="./images/img-9.jpg"
text="Explore the hidden waterfall deep inside the Amazon jungle"
label="Adventure"
path="/services"
/>
src/Components/Cards/CardItem.js
const { src, text, label, path } = props
return (
<>
<li className="cards__item">
<Link className="cards__item__link" to={path}>
<figure className="cards__item__pic-wrap" data-category={label}>
<img src={ src } alt="Travel" className="cards__item__img" />
</figure>
<div className="cards__item__info">
<h5 className="cards__item__text">{text}</h5>
</div>
</Link>
</li>
</>
)
Even though no error is being displayed, the image simply does not appear.
How can I correctly store the images folder and access resources from .css and .js files?