简体   繁体   中英

Styling mat-tab labels -Angular Material

I'm trying to figure out how to change the color of the mat-tab labels. I've gone through every stack overflow post related to styling mat-tabs, but none of the solutions have changed the text color from white to black; Right now it looks like this. You can't even see the non-active tabs. 在此处输入图片说明

How can I get the non-active links to show up as the color black?

<div class="buttonRow">
  <mat-tab-group id="linkLabel" mat-stretch-tabs class="example-stretched-tabs mat-elevation-z4" >
    <div class="tabContent" >
      <mat-tab id="tab1" label="Tab1" >  Content 1 </mat-tab>
      <mat-tab id="tab2" label="Tab2"> Content 2 </mat-tab>
      <mat-tab id="tab3" label="Tab3"> Content 3 </mat-tab>
    </div>
    </mat-tab-group>

</div>

css I'm using that's currently working

::ng-deep.mat-tab-label.mat-tab-label-active:not(.mat-tab-disabled),
::ng-deep.mat-tab-label.mat-tab-label-active.cdk-keyboard-focused:not(.mat-tab-disabled) {
  background-color: green;

  color: white;
  opacity: 1;
}

End result of answer by Nathan

最终结果

Use it this way:

::ng-deep .mat-tab-list .mat-tab-labels .mat-tab-label-active {
  color: red;
  background-color: green;
}

Stackblitz example

** Note: Apply these styles in styles.scss**


**Active tab label colour changes:**

.mat-tab-label-active 
{
    color: #00ADEE !important;
} 

**To remove the border for the tabs:**

.remove-border-bottom .mat-tab-header 
{
    border-bottom: none;
}

**To chnage the colour of the ink bar(tab border):**

.mat-tab-nav-bar:active
{
    color: #00ADEE !important;
}
** To specify the height && color for the ink bar:**  

.mat-ink-bar{
    background-color: #00ADEE !important;
    display:block;
    height: 8px !important;
}

You might need to set the active text color to white instead

.mat-tab-label.mat-tab-label-active {
   color: #ffffff;
}

Then change the default label color to black

.mat-tab-label {
  color: #000000;
}

无需使用 ng-depp 或使用全局样式,只需使用 mat-tab-label 指令,如本例所示: https : //material.angular.io/components/tabs/overview#tab-group-custom-标签

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM