代码之家  ›  专栏  ›  技术社区  ›  Cacoon

角2材质的粘性页脚

  •  9
  • Cacoon  · 技术社区  · 8 年前

    我尝试了几种方法,包括: https://david-kerwick.github.io/2017/01/14/material-2-flex-layout-making-a-sticky-footer.html 我测试过的与此相关的大多数问题都失败了,或者根本不起作用。

    <div class="content">
      <app-navbar></app-navbar>
      <app-footer></app-footer>
    </div>
    

    和 <app-content></app-content>

    整个应用程序导航栏如下所示:

    <mat-sidenav-container fullscreen>
    
      <mat-sidenav mode="push" #sidenav>
        <div fxLayout="column">
          <mat-toolbar fxLayoutAlign="center center" color="primary">
            <button mat-icon-button routerLink="/home" (click)="sidenav.close()">
              <mat-icon>keyboard_backspace</mat-icon>
            </button>
          </mat-toolbar>
          <button mat-button routerLink="/dashboard" (click)="sidenav.close()" >Information</button>
          <button mat-button routerLink="/second" (click)="sidenav.close()" >Web tools</button>
        </div>
      </mat-sidenav>
      <mat-toolbar color="primary" class="fixed-navbar mat-elevation-z10">
        <button mat-icon-button (click)="sidenav.open()" fxHide="false" fxHide.gt-xs>
          <mat-icon>menu</mat-icon>
        </button>
    
        <div fxLayout="row">
          <button fxLayout="flex-shrink: 0;" mat-button class="title" style="font-size: 25px;">{{this.title}}</button>
          <button fxShow="false" fxShow.gt-xs mat-button routerLink="/dashboard" [matMenuTriggerFor]="infoMenu">Information</button>
          <button fxShow="false" fxShow.gt-xs mat-button routerLink="/second" [matMenuTriggerFor]="toolsMenu">Web tools</button>
        </div>
        <!-- fxFlex will fill the empty space and push the following items to the right -->
        <div fxFlex></div>
        <button mat-icon-button>
          <mat-icon>face</mat-icon>
        </button>
      </mat-toolbar>
      <app-container></app-container>
    
    </mat-sidenav-container>
    

    <mat-toolbar>
      <div class="container">
        <span>this is a toolbar</span>
      </div>
    </mat-toolbar>
    

    迄今为止,我唯一采用的造型是:

    @import url('https://fonts.googleapis.com/css?family=Comfortaa');
    .title {
      font-family: "Comfortaa";
    }
    html, body {
      height: 100%;
      margin: 0;
    }
    .content {
      min-height: 100%;
    }
    

    3 回复  |  直到 8 年前
        1
  •  30
  •   Can    8 年前

    使用Flexbox的方法:

    当我们使用Flexbox时,我们可以得到一个 清洁工 解决方案此外,我的解决方案将涵盖页面的第一个组件应该占据100%的高度。这通常需要适当地定位元素或使用背景。代码与Material 2的当前版本相匹配-在编写本文时,这是2.0.0-beta版本。12

    标记:

    <mat-sidenav-container class="all-wrap" fullscreen>
      <mat-sidenav #sidenav>
        <mat-list>
          <mat-list-item [routerLink]="['/']"> Foo</mat-list-item>
          <mat-list-item [routerLink]="['/bar']"> Bar</mat-list-item>
        </mat-list>
      </mat-sidenav>
    
      <div class="page-wrap">
        <header role="banner">
          <mat-toolbar color="primary">
            <button
              type="button"
              mat-icon-button
              (click)="sidenav.open()"
              title="Open sidenav">
              <mat-icon>menu</mat-icon>
            </button>
            Your Toolbar
          </mat-toolbar>
        </header>
        <main class="content">
          <router-outlet></router-outlet>
        </main>
        <footer>
          Your sticky footer with a variable height.
        </footer>
      </div>
    </mat-sidenav-container>
    

    /*
     * Actual Sticky Footer Styles
     */
    .all-wrap {
      min-height: 100vh;
    }
    
    .page-wrap {
      display: flex;
      flex-direction: column;
      min-height: 100vh;
    }
    
    .content {
      flex: 1;
    }
    
    
    /*
     * Make the Component injected by Router Outlet full height:
     */
    main {
      display: flex;
      flex-direction: column;
      > *:not(router-outlet) {
        flex: 1;
        display: block;
      }
    }
    

    您可以在 Blogpost 这是我写的,因为我对我在这里找到的解决方案不满意。还有一个 demo

        2
  •  4
  •   Emeric    7 年前

    应用程序。组成部分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>
    

    html, body {
        height: 100%;
        box-sizing: border-box;
        margin: 0;
    }
    

    另一种选择 如果您喜欢填充页脚而不是内容:

    应用程序。组成部分html:

    <div fxLayout="column" style="height: 100%;">
        <app-header></app-header> // your header
        <router-outlet></router-outlet> // your content
        <app-footer fxFlexOffset="auto"></app-footer> // your footer
    </div>
    

    html, body {
        height: 100%;
    }
    
        3
  •  0
  •   Cacoon    8 年前

    答案可以在这里找到: Sticky footer at the bottom in Angular 2

    解决方案

    app {
      min-height: 100%;
      width: 100%;
      margin-bottom: -271px;
      display: table;
    }
    
    header-main,
    router-outlet,
    footer{
      display: table-row;
    }
    
    header-main {
     height: 60px;
    }
    
    router-outlet {
      position: absolute;
    }
    
    footer {
      height: 271px;
    }