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:
Page showing the toolbar alone, the shadow is rendered:
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>
Add this in your styles:
.mat-toolbar {
position: relative;
z-index: 2;
}
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>
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>
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With