Angular 2-全局CSS文件 [英] Angular 2 - Global CSS file

查看:170
本文介绍了Angular 2-全局CSS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以向Angular 2添加全局CSS文件? 目前,我有许多具有相同按钮样式的不同组件-但是每个组件都有自己的样式CSS文件.令人沮丧的改变.

Is it possible to add a global CSS file to Angular 2? At the moment I have many different components that have the same button styling - but each of the components have their own CSS file with the styling. This is frustrating for changes.

我在Stack Overflow的某处读到要添加的内容:

I read somewhere on Stack Overflow to add:

import { ViewEncapsulation } from '@angular/core'; //add this

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  encapsulation: ViewEncapsulation.None            //add this
})

因此,我在根组件中添加了ViewEncapsulation行,然后将CSS样式添加到了根应用CSS(app.component.css)中,并从单个组件CSS文件中删除了CSS样式,但这没有用.

So I added the ViewEncapsulation lines in the root component, then added the CSS styling to the root app CSS (app.component.css) and removed the CSS styling from individual component CSS files, and it did not work.

肯定有一种添加全局CSS文件的方法吗?我是否需要在各个组件中添加一些内容以使它们访问全局CSS文件?

Surely there is a way to add a global CSS file? Do I need to add something to the individual components to make them access the global CSS file?

推荐答案

您可以简单地将css导入主html文件中.

You can simply import the css in the main html file.

这篇关于Angular 2-全局CSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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