15

Is it possible to change the inkbar color of the active tab?

By default the ink bar is blue. See here for an example.

I tried this in SCSS, but it doesn't work.

.mat-tab-label-container{
  .mat-tab-list{
    .mat-ink-bar {
      background-color: green
    }
  }
}

.mat-tab-label-active{
 color: green 
}

Anyone can please help,

Edric
  • 24,639
  • 13
  • 81
  • 91
Mark
  • 181
  • 1
  • 1
  • 11

5 Answers5

29

ImageThis could be similar to what you want to achieve

Please see this link ( Cannot style mat-tab without ::ng-deep and !important ) and upvote if it helps you, I think this is similar to what you want to achieve.


To answer your question

You need to use Selector specificity and then put your style in the root style /src/styles.css (NOTE: that don't put it in the components styleUrls your style will not work)

to style the ink bar

.mat-tab-group.mat-primary .mat-ink-bar, .mat-tab-nav-bar.mat-primary .mat-ink-bar{
  background: yellow;
  height: 10px;
} 


Change ink-bar from underline to elliptical covering the item

You can try this code to make it elliptical to cover the item.

/* label style */
.mat-tab-label{
  background: #e7e7e7;
  color:  black;
  min-width: 60px!important;
}
/* focus style */
.mat-tab-group.mat-primary .mat-tab-label:not(.mat-tab-disabled):focus, .mat-tab-group.mat-primary .mat-tab-link:not(.mat-tab-disabled):focus, .mat-tab-nav-bar.mat-primary .mat-tab-label:not(.mat-tab-disabled):focus, .mat-tab-nav-bar.mat-primary .mat-tab-link:not(.mat-tab-disabled):focus{
  background: #e7e7e7;
}
/* ink bar style */
.mat-tab-group.mat-primary .mat-ink-bar, .mat-tab-nav-bar.mat-primary .mat-ink-bar{
   background: rgba(149, 165, 166,0.3);
    height: 35px;
    border-radius: 100px;
    margin-bottom: 5px;
} 

Please see the live sample here.

https://stackblitz.com/edit/dmgrave-ng-so-anser-tabs-style?file=styles.css

Hope this helps.

davecar21
  • 2,606
  • 21
  • 33
3

Below Lines worked for me. It is recommended to use ::ng-deep. It will be applied to child components:

::ng-deep .mat-tab-group.mat-primary .mat-ink-bar {
    background-color: rgb(39, 184, 176) !important;
}
Akif
  • 7,098
  • 7
  • 27
  • 53
0

use ::ng-deep

::ng-deep .mat-tab-group.mat-primary .mat-ink-bar, .mat-tab-nav-bar.mat-primary .mat-ink-bar {
    background-color: #00d440;
}
0

In Material >= 15 use this:

.mat-mdc-tab:not(.mat-mdc-tab-disabled) .mdc-tab-indicator__content--underline, .mat-mdc-tab-link:not(.mat-mdc-tab-disabled) .mdc-tab-indicator__content--underline {
  border-color: #0A94D0;
}
Zoidy
  • 362
  • 4
  • 21
0

If you want to do it without SCSS, you can add color to the mat-tab-group and it will change the color of the .mat-ink-bar:

<mat-tab-group mat-align-tabs="start" color="accent">

It will take the corresponding color of your theme then.

Bullsized
  • 362
  • 4
  • 7