如何通过 Flex-Layout 设置 Angular Material Footer

Pax*_*rce 14 html css angular-material angular-flex-layout angular

如何在我的应用程序中设置页脚(我使用 Angular Material),以便它:

  1. 如果内容高度小于视口,则粘在底部
  2. 如果内容高度超过视口,则向下移动/被向下推

更重要的一件事 - 我想通过angular/flex-layout来实现这一点,而不是通过标准的 HTML/CSS 'flex-box'。

<mat-sidenav-container>
  <mat-sidenav #sidenav
    fixedInViewport="true"
    [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
    [mode]="(isHandset$ | async) ? 'over' : 'side'"
    [opened]="!(isHandset$ | async)">

    <mat-nav-list>
      <mat-list-item *ngFor="let li of listItems" routerLink="{{li.link}}">
        <mat-icon mat-list-icon>{{li.icon}}</mat-icon>
        <p mat-line>{{li.name}}</p>
      </mat-list-item>
    </mat-nav-list>
  </mat-sidenav>
  <mat-sidenav-content>

    <app-header (menuButtonClick)="sidenav.toggle()"></app-header>

    <ng-content select="[outlet]"></ng-content>

    <app-footer></app-footer>

  </mat-sidenav-content>
</mat-sidenav-container>   
Run Code Online (Sandbox Code Playgroud)

谢谢你们。

Cur*_*rse 17

如果您更喜欢填充内容而不是页脚(Akhi 的解决方案),这里有几行解决方案:

app.component.html:

<div fxLayout="column" fxFlexFill>
    <app-header></app-header> // your header
    <div fxFlex>
        <router-outlet></router-outlet> // your content
    </div>
    <app-footer></app-footer> // your footer
</div>
Run Code Online (Sandbox Code Playgroud)

样式.css:

html, body {
    height: 100%;
    box-sizing: border-box;
    margin: 0;
}
Run Code Online (Sandbox Code Playgroud)


Akh*_*Akl 10

通过添加 使容器flex和方向并使页脚粘在底部columnfxLayout="column"fxFlexOffset="auto"

  <mat-sidenav-content fxLayout="column">

    <app-header (menuButtonClick)="sidenav.toggle()"></app-header>

    <ng-content select="[outlet]"></ng-content>

    <app-footer fxFlexOffset="auto"></app-footer>

  </mat-sidenav-content>
Run Code Online (Sandbox Code Playgroud)