css - 我在我的 react js 中添加了背景图片。但它显示一个错误
问题描述
我在互联网上看到他们告诉要在公用文件夹中添加图像。所以我通过创建一个子文件夹名称 img 将我的图像添加到公共文件夹中,我将我的图像“mario.png”放入其中。
因为我想将该图像添加为背景图像,所以我在 index.css 中编写了这段代码
body{
margin:0;
padding: 0;
font-family: sans-serif;
background: url(/img/mario.png);
background-size: 100%;
background-position: bottom;
background-color: #95e8f3;
min-height: 100%;
}
但它仍然没有工作它显示错误:** ./src/index.css (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-4-1!./ node_modules/postcss-loader/src??postcss!./src/index.css) 错误:无法解析 'D:\Users\PIRATES\Desktop\cool\src' 中的 '/img/mario.png' **
但是当我在 src 中创建一个资产文件夹时,它正在工作,但我想知道为什么当我将图像放在公用文件夹中时它不工作。
解决方案
您没有url
正确使用功能。文档
body{
margin:0;
padding: 0;
font-family: sans-serif;
background: url("/img/mario.png");
background-size: 100%;
background-position: bottom;
background-color: #95e8f3;
min-height: 100%;
}
推荐阅读
- audio - 将音频从 java 服务器实时流式传输到 Android 客户端
- python - 获取 Pandas 中每一天的上个月平均值
- c# - 使用 AES 返回随机字符从文件中解密日期
- zk - 如何使用 ZK 框架关闭浏览器窗口?
- android - 如何为 Android 可绘制对象设置半透明颜色
- android - 如何检测Here SDK地图小平底锅并忽略它们
- javascript - javascript对象数组通过特定键值获取uniq值
- amazon-web-services - 使用 ElasticBeanStalk 在 AWS 上进行蓝绿部署
- html - 图像在 div 下消失
- amazon-web-services - 使用作业书签的 AWS Glue 失败并显示“数据源不支持编写空或嵌套的空架构”