在angular4中导入样式表 [英] Importing style sheets in angular4
问题描述
我正在尝试将我的项目从angular JS升级到angular4.我有一些样式表,这些样式表已在angular JS项目中使用.
Am trying upgrade my project from angular JS to angular 4. I have style sheets which i have used in angular JS project.
这是我的文件夹结构
我使用角度CLI创建了组件. 一切正常,但我不知道如何在angular 4项目中使用我的样式. 有人可以解释一下如何在全球范围内使用样式吗?并且仅在某些组件中?
I created components using angular CLI. Everything works perfect but i don't know how to use my styles in angular 4 project. Can some one explain how i can use my styles globally? and also only in certain components?
推荐答案
您可以在angular-cli.json
中添加样式:
"styles": [
// Your styles go here
]
这是针对全局样式的.本地样式(针对某个组件)在符合您要求的CSS文件中,该文件属于您的组件,例如 foo.component.css .默认情况下,每个组件都具有以下注释:
This is for global styles. Local styles (for a certain component) are within the accordant CSS-file, which belongs to your component, e.g. foo.component.css. By default each component has the following annotation:
@Component({
selector: 'app-foo',
templateUrl: './foo.component.html',
styleUrls: ['./foo.component.css'],
})
因此, foo.component.css 包含组件FooComponent
的CSS.
So, foo.component.css contains the CSS for the component FooComponent
.
在这里看看:
- Component Styles
- Global styles
这篇关于在angular4中导入样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!