angular-cli how to add global styles?
As of the beta.14 release of the CLI (which uses Angular 2.0 final), a global stylesheet can be linked inside angular-cli.json
under the "styles" key. This is a reference to a file relative to the src/
directory, which is style.css
by default.
Leveraging this method you could:
- Copy the global styles into
src/styles.css
- Use CSS imports to import external rules into
styles.css
- Add more global styles via the
apps[0].styles
property inangular-cli.json
See also Global Styles in angular-cli
's wiki.
How to @import CSS file in Angular?
If you want to point to a css/scss file within a component, you can add a shortcut to your styles folder in your angular.json in the options
node like so :
"my-app": {
"root": "...",
"sourceRoot": "...src",
"projectType": "application",
"architect": {
"build": {
[...]
"options": {
[...]
"stylePreprocessorOptions": {
"includePaths": [
"projects/my-app/src/styles" // path to your styles folder
]
}
}
},
}
},
Then, whenever you use @import "...";
, it will start from the css
folder, so you can use @import "theme.scss";
Is it better to import styles in angular.json or importing in styles.scss?
If you add your CSS imports in the angular.json
file, think of it as adding multiple global css files for your project.
But if you add your CSS imports in the styles.css
file, you will have one global stylesheet for your angular project but you will refer multiple stylesheets in it.
I personally refer my stylesheets in the angular.json
file as I find it easy to maintain the custom global CSS that I write as apposed to importing multiple global CSS stylesheets such as bootstrap
Angular 2/4 : How to load css file from Assets
I got same error once I have started Angular 4 project
What I have done is
In my assets there is no css
"assets": [
"assets",
"favicon.png"
],
And in style
"styles": [
"../src/assets/css/main.css",
]
And then please do ng serve again
Hope this helps
Angular - including CSS file in index.html
Angular CLI have it's own way to initialize your global css/js.
They are located in .angular-cli.json
configuration
Locate "styles":
and add your css there
Example :
"styles": [
"../node_modules/angular2-busy/build/style/busy.css",
"styles.css"
],
Hope that helps.
Related Topics
Why Does Firefox Treat Helvetica Differently from Chrome
How to Select CSS Id's with Numbers in Them
Vuejs: Complete Dynamic Component Transition Before Rendering New Component
CSS Firefox - How to Deactivate The Dotted Border ( Firefox Click Indicator )
Angularjs: with Ng-Animate & Ng-View, How to Make a 3D Cube Rotation Effect
Apply CSS Properties When Transition Ends
CSS Content Property Not Displaying
Force Nested Divs to Have Min-Height of 100%
Angular 6 Load CSS Folders in Angular.JSON
How to Make a Flexbox Container That Stretches to Fit Wrapped Items
Working with CSS Floats in HTML2Pdf
How to Style Ng-Bootstrap - Alternative to /Deep/
How to Make a Div Full Screen and Scrollable
How to Change The Color of Bootstrap Checkbox
CSS - Border Radius and Solid Border Curved Inside