简体   繁体   English

Angular CLI映像未在CSS中加载

[英]Angular CLI images not loading in css

Getting "404 Not Found" Error when trying to reference an image(lead-bg.jpg) from "assets/images" Project Structure directory in my Angular CLI Project.Whereas i am able to open the image in VS Code. 尝试从我的Angular CLI Project中的 “资产/图像” 项目结构目录中引用图像(lead-bg.jpg)时出现“ 404未找到”错误。我可以在VS Code中打开图像。 This is on my local machine. 这是在我的本地机器上。 Also the same kind of issue happened to me with the .woff and .ttf fonts as well. 同样,.woff和.ttf字体也发生了同样的问题。

As i see server is trying to look for the image at localhost folder instead of the "assets/images" directory where there is no such folder for images. 如我所见,服务器正在尝试在localhost文件夹而不是“ assets / images”目录中查找图像,在该目录中没有此类图像文件夹。

Please help me out with this issue as i have put on hold many angular projects due to this issue.. 请帮我解决这个问题,因为由于这个问题我搁置了许多有角度的项目。

Thanks!!! 谢谢!!!

You are referring the wrong path. 您指的是错误的路径。 try this 尝试这个

 background-image: url(./assets/images/lead-bg.jpg);

. => current path =>当前路径

./assets => navigate to assets folder from the current path ./assets =>从当前路径导航到资产文件夹

./assets/images/lead-bg.jpg => then to original image path ./assets/images/lead-bg.jpg =>然后转到原始图像路径

.. => points to the parent folder from current directory which is above assets but not assets folder. .. =>指向当前目录中位于资产上方的父文件夹,而不是资产文件夹。

I think you are missing the quotes. 我认为您错过了报价。

Try background-image: url("../images/lead-bg.jpg"); 尝试使用background-image: url("../images/lead-bg.jpg");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM