在使用Visual Studio 2017 Angular模板制作的Angular 2应用程序中的何处添加全局CSS [英] Where to add global css in an Angular 2 application made with Visual Studio 2017 Angular template

查看:132
本文介绍了在使用Visual Studio 2017 Angular模板制作的Angular 2应用程序中的何处添加全局CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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.htmlstyles.css.因此,这两个文件是全局文件.您可以通过styles.css中的@importindex.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆