![](/img/trans.png)
[英]How to inherit css styles in child component from parent in Angular 5
[英]How to change styles of child mat angular component?
正如 angular 官方文檔所說, ::ng-deep , >>>, /deep/
已棄用,很快將被刪除:
https://angular.io/guide/component-styles#deprecated-deep--and-ng-deep
如果我使用像<mat-checkbox>
這樣的mat
組件或更全面的像<mat-table>
這樣的組件,我怎么能從父組件對該組件進行一些更改?
.SCSS
文件中編寫樣式嗎?inner
材質角度組件的樣式?正如提及文檔所說,您可以將::ng-deep
與:host
結合使用,這樣就可以了。
為了將指定的樣式范圍限定到當前組件及其所有后代,請確保在
::ng-deep
之前包含:host
選擇器。 如果在沒有:host
偽類選擇器的情況下使用::ng-deep
組合器,則樣式可能會滲透到其他組件中
:host /deep/ h3 {
font-style: italic;
}
但是,您也可以使用自定義CSS
類和id將自定義 css 應用於Angular Material Components上的.CSS
或.SCSS
文件。 將.class
& #id
與mat
默認類結合使用是有效的。 此外,您可以在組件樣式文件( .CSS
或.SCSS
)中使用自定義 Angular 材質類來覆蓋如下所示:
.app-component-style {
/* All the CSS here */
.mat-tab-group .mat-tab-label {color: green;}
}
所以,繼續使用它作為Dudewad在這里提到的: https : //stackoverflow.com/a/49308475/4185370
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.