Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mat-Nav-List horizontal instead of vertical?

How do I make the following horizontal instead of the (apparent default) of vertical? It is located within navigation.component.html within my Angular 5.2.7 application that was generated via Angular-CLI 1.7.2. The documentation link included in the comment does not discuss how to layout a Material navigation bar horizontally.

<mat-nav-list>
  <!--https://material.angular.io/components/list/overview-->
  <mat-list-item>
    <a [routerLink]="['/home']">Home</a>
  </mat-list-item>
  <mat-list-item>
    <a [routerLink]="['/about']">About</a>
  </mat-list-item>
  <mat-list-item>
    <a [routerLink]="['/contact']">Contact Us</a>
  </mat-list-item>
</mat-nav-list>
like image 270
user3785010 Avatar asked Mar 07 '18 20:03

user3785010


2 Answers

I used FlexBox setting fxLayout="row" (or just put in fxLayout as default is row)

<mat-nav-list fxLayout="row">
     <a mat-list-item href="#">One</a>
     <a mat-list-item href="#">Two</a>
</mat-nav-list>

However, this is using Angular Flex-Layout so an extra package

like image 187
Zeid Shubailat Avatar answered Oct 18 '22 19:10

Zeid Shubailat


I was able to create a horizontal mat-nav-list by using some custom scss. I attach it using the class list-horizontal.

<mat-nav-list class="list-horizontal">
  ...
</mat-nav-list>

Here's the scss I used for list-horizontal:

mat-nav-list.list-horizontal {
  padding: 0;
  .mat-list-item {
    display: inline-block;
    height: auto;
    width: auto;
  }
}

Here's a Stackblitz to show it working with Angular Material 7.

like image 16
FirstVertex Avatar answered Oct 18 '22 19:10

FirstVertex