在使用Visual Studio 2017 Angular模板制作的Angular 2应用程序中的何处添加全局CSS [英] Where to add global css in an Angular 2 application made with Visual Studio 2017 Angular template
问题描述
我是Angular的新手,我已经使用Visual Studio 2017 Angular Spa模板创建了Angular 2应用程序.
I'm new in Angular and I have created an Angular 2 application using Visual Studio 2017 Angular Spa template.
我想将Angular Material添加到我的项目中,并且在其指南中说我必须添加以下内容:
I want to add Angular Material to my project and in its guide said that I have to add this:
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
但是我不知道在哪里.
我已将其添加到app.component.css
文件中:
I have add it inside app.component.css
file:
@import url("https://fonts.googleapis.com/css?family=Roboto:300,400,500");
但是我得到警告:
(CssLint)@import阻止并行下载,请改用.
(CssLint) @import prevents parallel downloads, use instead.
我已经找到了这个答案,但是我认为这不适用于我的问题.
I have found this answer, but I don't think it applies to my problem.
在哪里可以添加样式或字体以在全球范围内使用它们?
Where can I add styles or fonts to use them globally?
推荐答案
在Angular项目文件夹中,您应该进入src/app/
.在app
文件夹中,您可以看到index.html
和styles.css
.因此,这两个文件是全局文件.您可以通过styles.css
中的@import
在index.html
od中添加字体样式.
In your Angular project folder you should got to src/app/
. In the app
-folder you can see index.html
and styles.css
. So this two files are global. You can add font styles in index.html
od via @import
in styles.css
.
如果有问题,您应该在wwwroot
文件夹中有一个index.html
.在
In case of your question you should have an index.html
in your wwwroot
folder. In this example the author does so.
例如index.html
:
<html>
<head>
....
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
...
</head>
<body>
...
</body>
</html>
这篇关于在使用Visual Studio 2017 Angular模板制作的Angular 2应用程序中的何处添加全局CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!