Angular 2 material mat-tab size

后端 未结 5 1513
温柔的废话
温柔的废话 2021-02-04 01:35

I have the following piece of code

  
    
相关标签:
5条回答
  • 2021-02-04 02:03

    Try this:

    /deep/.mat-tab-label, /deep/.mat-tab-label-active{
     min-width: 0!important;
     padding: 3px!important;
     margin: 3px!important;
    }
    

    NOTE: In angular 8 /deep/ not working... you can use ::ng-deep, like so:

    ::ng-deep.mat-tab-label, ::ng-deep.mat-tab-label-active{
     min-width: 0!important;
     padding: 3px!important;
     margin: 3px!important;
    }
    
    0 讨论(0)
  • 2021-02-04 02:07

    In my case the accepted answer didn't work well - when switching between tabs the width of body of specific tab was changing and it didn't look nice, so I added mat-tab-link to resolve it

    ::ng-deep.mat-tab-link,  ::ng-deep.mat-tab-label, ::ng-deep.mat-tab-label-active{
        min-width: 97px!important;
    }
    
    0 讨论(0)
  • 2021-02-04 02:09

    If you want to control the height and width of angular material tabs use styles followed by ::ng-deep. Check the below code to modify height and width

    ::ng-deep .mat-tab-label
    {
      height: 27px !important;
      min-height: 5px!important;
      margin: 3px!important;
      width: 90px!important;
      min-width: 5px!important;
    }
    

    0 讨论(0)
  • 2021-02-04 02:10

    This worked for me

    .mat-tab-group > .mat-tab-header > .mat-tab-label-container > .mat-tab-list > .mat-tab
    labels {
      .mat-tab-label[role^='tab'] {
        min-width: 72px;
      }
    }
    
    0 讨论(0)
  • 2021-02-04 02:14

    Without !important:

    /* 
        ::ng-deep disables view-encapsulation of Angular components 
            -> to avoid global style bleeding use it in combination with :host
            -> https://angular.io/guide/component-styles#deprecated-deep--and-ng-deep
    */
    :host ::ng-deep .mat-tab-label {
        min-width: 100px;
    }
    
    0 讨论(0)
提交回复
热议问题