Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 + Material: mat-toolbar casts no shadow over mat-sidenav-container despite mat-elevation-z*

Trying to mimic the look of the Material guide, I can't get the toolbar's shadow to be rendered atop the mat-sidenav-container element:

Page showing toolbar and sidenav, but drop shadow isn't visible:

enter image description here

Page showing the toolbar alone, the shadow is rendered:

enter image description here

See the HTML code, it can't be more simple. What am I missing? Thanks...

app.component.html

<mat-toolbar class="mat-elevation-z6" color="primary">
  toolbar
</mat-toolbar>

<mat-sidenav-container >

  <!-- Side menu -->
  <mat-sidenav mode="side" opened="true">

    <h3>Menu 1</h3>
    <ul>

      <!-- Home (aka dashboard) -->
      <li>
        <a routerLink="/">dashboard</a>
      </li>

      <!-- Home (aka dashboard) -->
      <li>
        <a routerLink="/resolutions">resolutions</a>
      </li>
    </ul>

    <!-- List resolutions -->
    <h3>Menu 2</h3>
    <ul>
      <li>
        <a>incentive</a>
      </li>
    </ul>

  </mat-sidenav>

  <!-- Routed contents -->
  <div class="contents">
    <router-outlet></router-outlet>
  </div>

</mat-sidenav-container>
like image 653
Jem Avatar asked Oct 09 '17 13:10

Jem


4 Answers

Add this in your styles:

.mat-toolbar {
  position: relative;
  z-index: 2;
}
like image 111
Alex Nepsha Avatar answered Oct 14 '22 19:10

Alex Nepsha


had the exact same issue. I resolved it by adding the following class in my CSS:

.sidenav-container {
  z-index: -1 !important;
}

and added it to the mat-sidenav-container

<mat-sidenav-container class="sidenav-container">
...
</mat-sidenav-container>
like image 22
dda Avatar answered Oct 14 '22 19:10

dda


I solved the problem as follows:

CSS:

.tbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2;
}

Then in my template:

HTML:
<mat-toolbar class="mat-elevation-z6 tbar">
  ...
</mat-toolbar>
like image 20
yuro Avatar answered Oct 14 '22 19:10

yuro


If changing the z-index doesn't work, add the following class:

<mat-toolbar class="mat-elevation-z2"></mat-toolbar>

As per the angular guide: (https://material.angular.io/guide/elevation)

like image 39
FiringBlanks Avatar answered Oct 14 '22 18:10

FiringBlanks