Okey, so I think you did miss understand the way css works in angular. and are applying a css in an improper maner.
By telling that ViewEncapsulation.None
you're removing the shadow DOM angular is generating. Which, when the components get rendered, will apply his css to every other element.
@Component({
selector: 'app-custom-b',
templateUrl: './custom-b.component.html',
styleUrls: ['./custom-b.component.css'],
encapsulation: ViewEncapsulation.None, // <-- here
})
But this will only be applied when used.
A component, in Angular, should be able to leave on his own and should not impact other component (Not that way at least).
But if you wished to have a shared css file, you could do one of the following
1: Shared CSS
- Create a new
shared.component.css
file
- Add you css in there
:host {
.test-b {
background-color: pink;
}
}
- Use it in the component you wish.
2 : Global CSS
- Add global css in the
global_styles.css
file. this will change the teat-b
in your entire project
3 : Import exported css in the angular.json
file
- Open the
angular.json
file
- Add a new style to the
styles
array
"styles": [
"src/global_styles.css",
"new/path/to/my/project"
],
_here if you don't know how to export CSS _
None
Css will, when rendered, get applied to the entire project. prefer adding the component selector to avoid it having an impact in your project
app-custom-b {
// your css
}
Pro: Let you change the css of some children element that you would be able to change otherwise.
Con: Not that good for optimization.
Encapsulated
Will be created in a kind of Shadow DOM.
Pro: Optimized
Con: You cannot change css in some children element that are in their own shadow DOM.