css - mat-icon css 颜色样式不适用
问题描述
作为 Angular 的新手。我有一个疑问。在 Angular 4 中,我们有一个来自 MdIconModule 的 md-icon 标记,在后来的 Angular 版本中更改为 MatIconModule。
考虑 Angular 4 中的代码
app.component.html
<md-icon>add_alert</md-icon>
app.componentn.css
md-icon.add-alert{ color : purple }
在上面的代码中,图标已从黑色变为紫色。
但在 Angular 9 中,
app.component.html
<mat-icon>add_alert</mat-icon>
app.componentn.css
mat-icon.add-alert{ color : purple }
上面的代码没有改变颜色。而且我们需要手动在标签中添加类来改变颜色。
谁能解释原因
解决方案
您可以像这样将样式应用于 mat-icon
::ng-deep{
mat-icon {
font-size: 24px;
color: #3b86ff;
}
}
或者
.white-icon {
color: white;
}
/* Note: If you're using an SVG icon, you should make the class target the `<svg>` element */
.white-icon svg {
fill: white;
}
<mat-icon class="white-icon">menu</mat-icon>
推荐阅读
- azure-devops - 使用 Azure DevOps 时,如何防止 FtpUpload@2 在 ftp 服务器上创建额外的根文件夹?
- sql - 在 case 语句中聚合“不是 GROUP BY 表达式”错误
- r - 如何在R中的列表中查找包含和不包含的单词
- java - 结合二维数组和一维数组
- python - 打印满足特定条件的值的 colname 和 rowname
- mysql - 如何连接两个表以获得组合结果
- javascript - 用于字母矩阵输出的嵌套 for 循环
- azure-container-service - 如何使用 azcopy 更新 Azure 存储容器中的特定文件
- php - 从代码中发现所有使用过的 php 扩展
- multithreading - 显示长时间不返回的冗长后台作业的进度