Sticky footer in Angular 2 Material

后端 未结 3 1683
我在风中等你
我在风中等你 2021-02-09 00:00

I have been searching and searching for about 3 hours now because I didn\'t want to have to ask, but how can I keep a \'footer\' variable at the bottom but not like fixed at the

3条回答
  •  失恋的感觉
    2021-02-09 01:04

    An approach that uses Flexbox:

    When we utilize Flexbox we can get a cleaner solution. Also my solution will cover that the first component of your page should take 100% of the height. This is often needed to position elements appropriately or to work with backgrounds. The code matches the current version of Material 2 - at the time of writing this is 2.0.0-beta.12.

    Markup:

    
      
        
           Foo
           Bar
        
      
    
      
    Your Toolbar
    Your sticky footer with a variable height.

    Styles:

    /*
     * 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;
      }
    }
    

    You can find a more detailed description in a Blogpost that I wrote since I was unhappy with the solution I found here. There is also a demo.

提交回复
热议问题