What to use in place of ::ng-deep

后端 未结 7 875
梦毁少年i
梦毁少年i 2020-11-22 10:42

I\'m trying to style an element placed by the router outlet in angular and want to make sure that the element generated gets a width of 100%

From most of the replies

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 11:06

    This is not a general replacement for ::ng-deep, but for the use case described by the question author:

    In the special case where you want to style the element inserted by a router-outlet, there is an elegant solution using the adjacent neighbor selector in CSS:

    router-outlet+* {
      /* styling here... */
    }
    

    This will apply to all elements which are direct neighbors of a router-outlet.

    Further reading:
    https://developer.mozilla.org/en-US/docs/Web/CSS/Adjacent_sibling_combinator
    https://angular.io/guide/router#router-outlet

提交回复
热议问题