@Component({
...
...
...
encapsulations: ViewEncapsulation.None
})
when i use encapsulation like that it conflicts the default style in the other components in application.
When you load a component with ViewEncapsulation.None, its styles are applied to all the app.
So the answer is no, you can't...
But, what you can do is writing unique css style in your components style file, for example:
<app-toolbar></app-toolbar>
in your toolbar html you have something like:
<span>hello</span>
<div>My name is</div>
to apply styles only to this component write in its styles file:
app-toolbar span{
color: green;
}
app-toolbar div{
color: red;
}
or even better if you use scss files:
app-toolbar {
span {
color: green;
}
div {
color: red;
}
}
EDIT:
What you also could do and this works for sure (tested):
<app-toolbar></app-toolbar>
In this component html file (wrap all of its content in a div):
<div class="my-toolbar">
<span>hello</span>
<div>My name is</div>
</div>
Then in its style file:
.my-toolbar span{
color: green;
}
.my-toolbar div{
color: red;
}
or in scss format:
.my-toolbar {
span {
color: green;
}
div {
color: red;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With