How can I make it so only this `mat-card-subtitle` in this above header gets color red?

不羁岁月 提交于 2019-12-24 21:40:06

问题


I learn Angular material and I have this code

  <mat-card-header>
    <mat-card-title>Search for books</mat-card-title>
    <mat-card-subtitle>press enter on search</mat-card-subtitle>
  </mat-card-header>

and this css

.mat-card-subtitle {
  font-size: 10px;
  color: red;
}

The problem is now all <mat-card-subtitle> gets the color red. How can I make it so only the mat-card-subtitle in this above header gets color red?


回答1:


Add a custom CSS class in HTML

  <mat-card-header>
    <mat-card-title>Search for books</mat-card-title>
    <mat-card-subtitle class="red-text">press enter on search</mat-card-subtitle>
  </mat-card-header>

CSS

.red-text {
  font-size: 10px;
  color: red !important;
  text-align: center !important;
}



回答2:


Add a class to the mat-card-subtitle and give color to particular class

.classname{color:red}


来源:https://stackoverflow.com/questions/56734689/how-can-i-make-it-so-only-this-mat-card-subtitle-in-this-above-header-gets-col

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!