Add triangle at bottom of material design tab mat-ink-bar

。_饼干妹妹 提交于 2021-01-05 10:47:37

问题


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:


回答1:


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




回答2:


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`




回答3:


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

Try just this ^^...

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



来源:https://stackoverflow.com/questions/53554495/add-triangle-at-bottom-of-material-design-tab-mat-ink-bar

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