cssangularangular-template

How and where to use ::ng-deep?


How and where can one use ::ng-deep in Angular 4?

Actually I want to overwrite some of the CSS properties of the child components from the parent components. Moreover is it supported on IE11?


Solution

  • Usually /deep/ “shadow-piercing” combinator can be used to force a style down to child components. This selector had an alias >>> and now has another one called ::ng-deep.

    since /deep/ combinator has been deprecated, it is recommended to use ::ng-deep

    For example:

    <div class="overview tab-pane" id="overview" role="tabpanel" [innerHTML]="project?.getContent( 'DETAILS')"></div>
    

    and css

    .overview {
        ::ng-deep {
            p {
                &:last-child {
                    margin-bottom: 0;
                }
            }
        }
    }
    

    it will be applied to child components