1
votes

I want to change the style of the mat-ink-bar for Angular material tab.

I wanted to archieve a design like this: Jsfiddle example

The problem is that the mat-ink-bar already absolute positioned and i cannot display my ::after element. Is there a way how i can archieve this ?

Here is what i tried on stackblitz: Mat tab on stackblitz

my style are located inside the style.css. The triangle at the bottom is hidden if you use the dev tool. I could not show it using z-index.. Any help would be appreciated.

here the code:

css

.c-tab .mat-ink-bar {
  height: 5px;
}

.c-tab .mat-ink-bar::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    margin: 0 auto;
    width: 0;
    height: 0;
    border-top: solid 50px #3f51b5;
    border-left: solid 50px transparent;
    border-right: solid 50px transparent;
}

html

<mat-tab-group class="c-tab">
  <mat-tab label="First"> Content 1 </mat-tab>
  <mat-tab label="Second"> Content 2 </mat-tab>
  <mat-tab label="Third"> Content 3 </mat-tab>
</mat-tab-group>

should look like this: enter image description here

3
Could you please add relevant code in this post and not external links. position: absolute does not prevent you from using ::after - Code Spirit
@CodeSpirit i edited the post with the relevant html and css code - billyjov
please check its that work for you - harkesh kumar
@harkeshkumar. It should look like describe in my edited post - billyjov

3 Answers

2
votes

Update following css will resolve your issue.

.mat-tab-label {
  position: relative;
}
.mat-tab-header,
.mat-tab-label-container,
.mat-ripple {
  overflow: inherit !important;
}
.mat-ink-bar:after {
  content: "";
  position: absolute;
  top: 48px;
  right: 0;
  left: 0;
  margin: 0 auto;
  width: 0;
  height: 0;
  border-top: solid 20px #673ab7;
  border-left: solid 20px transparent;
  border-right: solid 20px transparent;
}

Checkout stackblitz

0
votes

You are missing display:block for your ::after element. So block properties dont apply. Additionally you are stretching the width of the ::after to match its parent by using top, left, right and bottom.

Position either to top left or bottom right, not both`

0
votes
.c-tab .mat-ink-bar {
  position:relative
}

Try just this ^^...

Theoretically that is all you need: updatet https://jsfiddle.net/Rakowu/e42wng0m/4/