1
I created the component toolbar with the following developer:
@Component({
    selector: 'app-toolbar',
    templateUrl: './toolbar.component.html',
    styleUrls: ['./toolbar.component.scss']
})
Note that the component is using the selector app-toolbar.
I added the following CSS to the file toolbar.component.scss:
app-toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2;
}
But the element nay was fixed at the top. When inspecting the element in the browser, I checked that it received the following attributes:
<app-toolbar _ngcontent-c0 _nghost-c1>
    //...
</app-toolbar>
When checking the generated CSS, it is being applied to the element app-toolbar but with a different attribute:
app-toolbar[_ngcontent-c1] {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2; 
}
That is, the element is rendered with the attribute _ngcontent-c0 and the CSS with the attribute _ngcontent-c1.
What’s wrong? Why is the element’s context different from the CSS context?
Thank you very much. I could complete your reply with an example using the
:hostand so would be more complete. I know enough in myscssdeclare the pseudo-class and within it the classes of the child elements, but for some this may not be very clear, the example would help.– Filipe Moraes
@Filipemoraes following your suggestion I complemented my reply.
– mercador