Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 material mat-tab size

I have the following piece of code

  <mat-tab-group>     <div *ngFor="let question of subcategory.questions">         <mat-tab label={{question.question_id}} class="question-tab">{{question.question}}</mat-tab>     </div>   </mat-tab-group> 

which displays like:

However I want to reduce tabs width, like this:

The problem is, when I change css at run time, it adjusts fine, but when I put css like:

.mat-tab {   min-width: 50px !important; } .mat-tab-label[_ngcontent-c9]{     min-width: 50px !important; } 

It doesn't work. Any idea how to approach this ?

like image 298
Aishwat Singh Avatar asked Jun 06 '17 09:06

Aishwat Singh


People also ask

What is Mat tab in angular?

Tabs and navigation While <mat-tab-group> is used to switch between views within a single route, <nav mat-tab-nav-bar> provides a tab-like UI for navigating between routes.

How do you conditionally prevent users from navigating to other tab in Mat tab group?

Let's say user did some changes in tab one and then tries to navigate to tab two, you can bind the second and third tab label with a (click) event which check if user has done some work or not, if yes then show the pop up which either saves the data(either save directly or route the user back to tab one) or discard, if ...


1 Answers

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; } 
like image 73
Shailesh Ladumor Avatar answered Oct 14 '22 13:10

Shailesh Ladumor