【发布时间】:2020-05-26 13:37:02
【问题描述】:
我尝试将图像作为我网站的背景图像,但它在这里不起作用是我在我的 css 中放置的:
.background {
background: url(assets/images/Forgot_password_2.PNG);
/*background-color: black;*/
width: 100%;
height: 100%;
}
这是我得到的错误:
错误 ./src/app/components/forgot-password/forgot-password.component.css 模块错误(来自 ./node_modules/postcss-loader/src/index.js): (发出的值而不是错误的实例) CssSyntaxError: C:\Users\hp\Documents\Projet 角度 8\f-g-habilitation\src\app\components\forgot-password\forgot-password.component.css:2:21: 无法解析“assets/images/Forgot_password_2.PNG” 'C:\Users\hp\Documents\Projet 角度 8\f-g-habilitation\src\app\components\forgot-password'
1 | .background {
2 |背景:网址(资产/图像/Forgot_password_2.PNG); | ^ 3 | /背景色:黑色;/ 4 |宽度:100%;
这是我的文件的架构:
我已经尝试过这里提到的解决方案(在 ../ 上已删除)但它不起作用:Angular 6 error: CSSSyntaxError - Failed to compile
有人可以帮我吗?
【问题讨论】:
-
网址不应该是字符串,
background: url("assets/images/Forgot_password_2.PNG"); -
这是背景图片,您错过了引号 '': background-image: url('path_to_the_image');
-
background: url('/assets/images/Forgot_password_2.PNG');对我有用 -
你好,我已经尝试过使用“”和“”,但它也不起作用
-
您的图像文件的文件名中有一个额外的空格(在文件扩展名之前和
2之后)。