Html Angular 2/4:如何从资产加载 css 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44136027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 14:40:38  来源:igfitidea点击:

Angular 2/4 : How to load css file from Assets

htmlcssangularassets

提问by user1814879

In my .angular-cli.json, I define this :

在我的 .angular-cli.json 中,我定义了这个:

"styles": [
  "node_modules/bootstrap/dist/css/bootstrap.min.css",
  "src/assets/css/main.css",
  "styles.css"
],

And in my assets folder I have (assets/css/*.css) .. But when i run my app, CSS doesn't loaded .. How can I resolve it please ? You can check jpeg file in attachment

在我的资产文件夹中,我有 (assets/css/*.css) .. 但是当我运行我的应用程序时,CSS 没有加载 .. 我该如何解决?您可以在附件中查看 jpeg 文件

enter image description here

在此处输入图片说明

回答by Jalay Oza

I got same error once I have started Angular 4 project

开始 Angular 4 项目后,我遇到了同样的错误

What I have done is

我所做的是

In my assets there is no css

在我的资产中没有 css

"assets": [
        "assets",
        "favicon.png"
      ],

And in style

而且很有风格

"styles": [
        "../src/assets/css/main.css",
]

And then please do ng serveagain

然后请再次发球

Hope this helps

希望这可以帮助

回答by Michelangelo

Ran also into this issue, but I did it differently. I did not modify the angular.json. I imported the url in styles.csswith @import url("./app/custom-styles/custom-bootstrap.css");. This way you don't need to restart for detection change. And you keep styles.cssclean for your general styling stuff.

也遇到了这个问题,但我的做法不同。我没有修改angular.json. 我styles.css@import url("./app/custom-styles/custom-bootstrap.css");. 这样您就不需要重新启动检测更改。并且你保持styles.css清洁你的一般造型。

Don't know if it is the best way, but for me it helped a lot to keep it clean.

不知道这是否是最好的方法,但对我来说,保持清洁很有帮助。

回答by Sujan

Go to assets folder then create new 'CSS folder & a styles.css file. Open 'angular.json' file give the path in "styles" section.

转到资产文件夹,然后创建新的“CSS 文件夹”和一个 style.css 文件。打开“angular.json”文件,在“样式”部分给出路径。

回答by arjun kumar mehta

always use double dots to go back. a single "../" use to go one directory back. Now check where is your assets folder from your destination folder. for me ../../assets/css/spinner.csshelped

总是使用双点返回。单个“../”用于返回一个目录。现在检查目标文件夹中的资产文件夹在哪里。对我有../../assets/css/spinner.css帮助