Angular 5 Stop background scrolling when mat-sidenav-container displayed


I’m creating a new Angular 5 site that has a mat-sidenav but i have an issue with it.

My mat-sidenav-container sits under my position: fixed main menu which is fine but if the page has a vertical scroll, if the mat-sidenav is displayed it too scrolls.

What i’m after is to stop the back content scrolling if the mat-sidenav is displayed but i don’t know the CSS to do this as i have tried all the position


    <mat-icon class="subMenuIcon" (click)="sidenav.toggle()" title="Click to open the sub-menu.">reorder</mat-icon>
    <img src="./assets/images/Crest.jpg">LEARNING SITE
    <div class="emptySpace"></div>        
    <mat-icon class="loggedInIcon">person</mat-icon>
    <span style="font-size: 15px">USERNAME</span>
    <mat-sidenav #sidenav mode="over" opened="false">
        <div class="closeButton">
            <mat-icon (click)="sidenav.toggle()" title="Click to close the sub-menu.">clear</mat-icon>
        <a (click)="sidenav.toggle()" routerLink="/">
        <a (click)="sidenav.toggle()" routerLink="search">


mat-sidenav {
    background-color: gray;
    margin-top: 64px;
    color: #ffffff;
    transition: 0.5s;
    padding: 7px;

mat-sidenav a {
    margin-top: 15px;
    margin-bottom: 15px;
    font-size: 17px;
    color: #ffffff;
    display: block;

mat-sidenav a:hover {
    color: #c41230;
    cursor: pointer;

.closeButton {
    text-align: right;
    margin-bottom: 15px;
    cursor: pointer;

.mat-drawer-container {
    position: static;

/* Moves the side-nav to below the main menu */
.mat-drawer-backdrop {
    margin-top: 64px !important;


Managed to do it with a bit of CSS. not bother that the back content scrolls but now my side-nav and backdrop do not move

CSS Used

.mat-drawer:not(.mat-drawer-side) {
    position: fixed;

.mat-drawer-backdrop {
    position: fixed !important;

Answered By – murday1983

Answer Checked By – Jay B. (AngularFixing Admin)

Leave a Reply

Your email address will not be published.