代码之家  ›  专栏  ›  技术社区  ›  core114

“角度材质”选项卡“放置下拉箭头的活动链接”

  •  1
  • core114  · 技术社区  · 6 年前

    stackblitz sample here

    <mat-tab-group>
      <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>
    

    css格式

    /* active tab */
    ::ng-deep .mat-tab-list .mat-tab-labels .mat-tab-label-active {
      color:#0f2241;
      background-color: lightgrey;
    }
    
    /* ink bar */
    ::ng-deep .mat-ink-bar {
      background-color:red !important; background:  url('../../../assets/sg-img/drop-down-arrow.png');
    }
    

    谢谢

    1 回复  |  直到 6 年前
        1
  •  4
  •   coreuter    6 年前

    而不是使用 ::ng-deep 将组件的ViewEncapsulation设置为none:

    import {Component, ViewEncapsulation} from '@angular/core';
    
    @Component({
      selector: 'tab-group-stretched-example',
      templateUrl: 'tab-group-stretched-example.html',
      styleUrls: ['tab-group-stretched-example.css'],
      encapsulation: ViewEncapsulation.None
    })
    export class TabGroupStretchedExample {}
    

    然后使用以下CSS(我不得不使用另一个箭头,因为您在stackblitz中使用了本地引用):

    .example-stretched-tabs {
      max-width: 800px;
    }
    /* active tab */
    .mat-tab-list .mat-tab-labels .mat-tab-label-active {
      color:#0f2241;
      background-color: lightblue;
      opacity: 1;
    }
    
    /* ink bar */
    .mat-tab-group.mat-primary .mat-ink-bar {
      background: none;
      content: url('https://image.flaticon.com/icons/svg/60/60995.svg');
      height: 10px;
    }
    

    这就是你想要的: stackblitz

    推荐文章