显示 mat-sidenav-container 时,Angular 5 停止背景滚动

mur*_*983 3 html css angular angular5

我正在创建一个新Angular 5网站,mat-sidenav但我遇到了问题。

我的mat-sidenav-container位于我的position: fixed主菜单下,这很好,但如果页面有垂直滚动,如果mat-sidenav显示它也会滚动。

我所追求的是停止后面的内容滚动,如果mat-sidenav显示,但我不知道CSS这样做,因为我已经尝试了所有position

HTML

<mat-toolbar>
    <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-toolbar>
<mat-sidenav-container>
    <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>
        </div>
        <a (click)="sidenav.toggle()" routerLink="/">
            <mat-icon>person</mat-icon>
            Dashboard
        </a>
        <a (click)="sidenav.toggle()" routerLink="search">
            <mat-icon>search</mat-icon>
            Search
        </a>
    </mat-sidenav>
</mat-sidenav-container>
<router-outlet></router-outlet>
Run Code Online (Sandbox Code Playgroud)

CSS

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;
}
Run Code Online (Sandbox Code Playgroud)

Gou*_*pal 8

添加fixedInViewport="true"mat-sidenav 可能会解决这个问题,也添加[style.marginTop.px]="56"


mur*_*983 0

设法用一点点做到了CSS。不介意后面的内容滚动,但现在我的side-nav和背景不移动

使用的CSS

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

.mat-drawer-backdrop {
    position: fixed !important;
}
Run Code Online (Sandbox Code Playgroud)