【发布时间】:2021-09-10 23:07:51
【问题描述】:
当我希望特定部分具有我在公共文件夹内的图像文件夹中的背景图像时,我正在创建一个反应应用程序。访问这些图像似乎可以正常工作,除非我尝试从 App.css 访问它们
错误:编译失败。
./src/App.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-4-1!./node_modules/postcss-loader/src??postcss! ./src/App.css) 错误:无法解析“C:\Users\shlok\OneDrive\Desktop\React\react-website-1\src”中的“/images/img-2.jpg”
App.css
.services {
background-image: url('/images/img-2.jpg');
background-position: center;
background-size: cover;
background-repeat: no-repeat;
color: #fff;
font-size: 100px;
}
.products {
background-image: url('/images/img-1.jpg');
background-position: center;
background-size: fill;
background-repeat: no-repeat;
color: #fff;
font-size: 100px;
}
.sign-up {
background-image: url('/images/img-8.jpg');
background-position: center;
background-size: cover;
background-repeat: no-repeat;
color: #fff;
font-size: 100px;
}
【问题讨论】: