I've got a custom component <ui-title>
that I wish to style differently based on what its direct parent element is.
For example, if it appears within <ui-section>
, style it YELLOW. Within <ui-card>
style it BLUE. If it appears anywhere else, style it GREEN.
Here's what I've tried:
:host {
background-color: green;
}
:host-context(ui-card) {
background-color: blue;
}
:host-context(ui-section) {
background-color: yellow;
}
This doesn't work because if an element is nested within both <ui-section>
and <ui-card>
because both sets of styles would be applied. I wish to apply a set of styles based strictly on the direct parent of the :host element.
Here's a StackBlitz that shows my issue.