5

I have this :

@Component({
    selector: 'host-element',
    template: `<elementA></elementA>`,
    styles:[''] //styles here
})

export class hostElement {}

How do I target the styles of elementA component from host-element?

Thanks in advance!!

2 Answers 2

10
:host elementA {
  // style here
}
Sign up to request clarification or add additional context in comments.

4 Comments

For me, this creates the result of "[__ngcontent-c3] elementA[__ngcontent-c3] { /*style here */ }", which just has the same result as if I had just put "elementA{ /*style here*/ }". How can I create the result of "[__ngcontent-c3] elementA { /*style here*/ }"?
looks like the other answer is what you are looking for
I had read elsewhere that the /deep/ operator was being depreciated, but I don't actually see anything about that in the angular docs, so looks like that should do it for me, thanks.
It's deprecated in Chrome, other browsers never supported it. Angular emulates it and doesn't depend on browser support, but it only works in ViewEncapsulation.Emulated (default)
4

Angular has a special css operator /deep/, you can read about it here.

To make a style go beyond your component, put in your css (sass, less):

/deep/ .elemet-a-class {
   ... your style;
}

Or if you want to put it locally, just

styles: ['/deep/ .element-a-class { ... }']

1 Comment

For newer versions use :host {}, as deep has been deprecated angular.io/guide/component-styles#deprecated-deep--and-ng-deep

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.