如何固定 mat-toolbar 和 mat-sidenav 并且在 mat-sidenav-content 中只有一个滚动条?

How to pin mat-toolbar and mat-sidenav and only have a scrollbar inside mat-sidenav-content?

有关相关应用,请参阅以下 StackBlitz:https://stackblitz.com/edit/angular-7cazwh?file=src%2Fapp%2Fapp.component.html

<div class="main-div">
  
  <mat-toolbar color="primary" class="app-header">
    <button mat-icon-button (click)="toggleSidenav()">
      <mat-icon>menu</mat-icon>
    </button>
    <span>Config</span>
    <span class="spacer"></span>
    <button mat-icon-button>
      <mat-icon>account_circle</mat-icon>
    </button>
    <span>Admin</span>
  </mat-toolbar>

  <mat-drawer-container class="app-sidenav">
    <mat-drawer #sidenav mode="side" opened="true" class="sidenav" fixedInViewport="false">
      <mat-list>
        <mat-list-item>
          <mat-icon matListIcon>people</mat-icon>Users
        </mat-list-item>
        <mat-list-item>
          <mat-icon matListIcon>devices_other</mat-icon>Devices
        </mat-list-item>
      </mat-list>
    </mat-drawer>
    <mat-drawer-content>
      <p style="margin:20px">TODO: mat-sidenav-content</p>
    </mat-drawer-content>
  </mat-drawer-container>

</div>
.spacer {
  flex: 1 1 auto;
}

.main-div {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
  height: 100vh;
}

.app-header {
  grid-column: 1 / 2;
  grid-row: 1 / 2;
}

.app-sidenav {
  grid-column: 1 / 2;
  grid-row: 2 / 3;
}

目前,当页面溢出时,我最终会在右侧看到滚动条,它跨越 header 区域(放置 mat-toolbar 的位置)和内容区域(其中 mat-sidenav-content 被放置)。如下图:

我想要的是滚动条仅显示在内容区域中,如下所示。我希望 header 和左侧菜单保持固定(当用户在溢出的内容中上下滚动时不移动):

此卷轴正在应用于您的 body 元素。您可能只想为 htmlbody 元素重置 marginpadding

body, html {
  padding: 0;
  margin: 0;
}

https://stackblitz.com/edit/angular-eddznu?file=src%2Fstyles.css