Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular material align menu tabs in the center

How can I align the mat menu tabs in the center?

f.e.

<mat-toolbar>
    <nav mat-tab-nav-bar aria-label="weather navigation links" [backgroundColor]="tabNavBackground">
        <a mat-tab-link routerLink="/lala">lala</a>
        <a mat-tab-link routerLink="/lala2">lala2</a>
        <a mat-tab-link routerLink="/lala3">lala3</a>
      </nav>
</mat-toolbar>
like image 703
Cap Barracudas Avatar asked Feb 04 '18 14:02

Cap Barracudas


People also ask

What is an active tab in Angular Material?

Angular Material tabs organize content into separate views where only one view can be visible at a time. Each tab's label is shown in the tab header and the active tab's label is designated with the animated ink bar. When the list of tab labels exceeds the width of the header, pagination controls appear to let the user scroll left ...

How do I align items in material-UI?

This guide focuses on aligning items in every conceivable way in Material-UI: aligning right, left, and horizontally centered; aligning top, bottom, and vertically centered. In this example I will use the Material-UI Grid, but the alignment principles apply for aligning all MUI components.

How to align the tabs in the center of the container?

If you want to align the tab labels in the center or towards the end of the container, you can do so using the [mat-align-tabs] attribute. You can control the duration of the tabs' animation using the animationDuration input.

How do I center align a column vertically in material UI?

Material-UI Align Left Let’s start by left aligning the first column with inline styling. The Grid Item in the top row will be vertically aligned top, the center row will be vertically aligned center, and the bottom row will be vertically aligned bottom. Ignore the className, it simply styles the borders on each item.


2 Answers

You can add mat-align-tabs="center" to the nav to make it center... See below...

<mat-toolbar>
 <nav mat-tab-nav-bar mat-align-tabs="center" aria-label="weather navigation links" [backgroundColor]="tabNavBackground">
    <a mat-tab-link routerLink="/lala">lala</a>
    <a mat-tab-link routerLink="/lala2">lala2</a>
    <a mat-tab-link routerLink="/lala3">lala3</a>
 </nav>
</mat-toolbar>
like image 101
Ron Avatar answered Oct 10 '22 06:10

Ron


You could use the CSS property flex.

Add this class e.g. in your styles.css or in the CSS file of your component:

.toolbar-flex {
  flex: 1 0.5 auto;
}

Your HTML would then look like:

<mat-toolbar>
    <span class="toolbar-flex"></span>
    <nav mat-tab-nav-bar aria-label="weather navigation links" [backgroundColor]="tabNavBackground">
        <a mat-tab-link routerLink="/lala">lala</a>
        <a mat-tab-link routerLink="/lala2">lala2</a>
        <a mat-tab-link routerLink="/lala3">lala3</a>
    </nav>
    <span class="toolbar-flex"></span>
</mat-toolbar>
like image 20
pzaenger Avatar answered Oct 10 '22 05:10

pzaenger