[英]Unable to apply simple CSS to an angular Materials element
這是Stackblitz。
我正在嘗試將 CSS color: blue
應用於類mat-button-toggle-label-content
的 div ,但它沒有得到應用。
類似的 CSS 已成功應用於名為mat-button-toggle-group
的父元素。
只需將顏色應用於mat-button-toggle
並將其保留在mat-button-toggle-group
mat-button-toggle-group {
background-color: orange;
mat-button-toggle {
color: blue;
}
}
您可以將樣式應用於.mat-button-toggle-label-content
但您需要打破Encapsulation
。
組件樣式被封裝。 您無法從組件外部訪問組件的樣式(類、ID)。 您需要刺入該組件並注入如下樣式
注意: /deep/ 已棄用,不再推薦。 所以你可以采用上述方法。 有關更多詳細信息,請查看組件樣式
mat-button-toggle-group {
background-color: orange;
/deep/ .mat-button-toggle-label-content {
color: blue;
}
}
有很多原因!
我的解決方案是你可能需要在 color: blue; 之后加上 !important
它是:顏色:藍色!重要;
只需將它移動到styles.scss
,它就會起作用Stackblitz 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.