29

I recognize that the Angular Material implementation is a work in progress, but I've spent some time this morning trying to get familiar with it. However, I'm really struggling to get the concepts shown in the demos to work in a stand alone site.

It seems that when the directives like <md-toolbar> and <md-content> are used in containers with fixed heights, then they work great. I'm struggling with how to throw them inside a <body tag and be able to have a sticky footer layout like in this example.

I've tried many variations, but here's one example that doesn't work when the content is removed from the DOM. When the content is there it grows beyond the viewport and the footer is placed afterwards like you'd expect. In the latest versions of Chrome and Firefox this example keeps the footer at the bottom when the content is removed, but in IE this just doesn't work at all. In IE the footer floats just below the header regardless of whether the main content is shown or not.

DEMO: http://codepen.io/sstorie/pen/xbGgqb

<body ng-app="materialApp" layou-fill layout='column'>
    <div ng-controller="AppCtrl" layout='column' flex>
      <md-toolbar class='md-medium-tall'>
        <div class="md-toolbar-tools">
          <span>Fixed to Top</span>
          <span flex></span>
          <md-button class="md-raised" ng-click="toggleContent(!displayContent)">toggle content</md-button>
        </div>
      </md-toolbar>
      <main class='md-padding' layout="row" flex>
        <div flex>
        <md-card ng-if="displayContent" ng-repeat = "card in cards">
          {{$index}}
          {{card.title}}
          {{card.text}}
        </md-card>
        </div>
               <div flex>
        <md-card ng-if="displayContent" ng-repeat = "card in cards">
          {{$index}}
          {{card.title}}
          {{card.text}}
        </md-card>
        </div>
      </main>
      <md-toolbar class="md-medium-tall">
        <div layout="row" layout-align="center center" flex>
          <span>FOOTER</span>
        </div>
      </md-toolbar>
    </div>
  </body>

Javascript:

angular.module('materialApp', ['ngMaterial'])

.controller('AppCtrl', function($scope) {
    $scope.cards = [
    {text: 'Bla bla bla bla bla bla bla ',
     title: 'Bla' },
    ...repeat 10 times...
  ];

    $scope.displayContent = true;

    $scope.toggleContent = function(showContent) { $scope.displayContent = showContent; };
});

CSS:

body {
    min-height: 100%;
    height: auto !important;
    height: 100%;
}

I'm definitely not a CSS guru, but it feels like this should be easy to do with the layout options in angular-material, so I'm hoping I'm really missing something obvious here.

Sam Storie
  • 4,444
  • 4
  • 48
  • 74

4 Answers4

25

There's no need for a bottom-sheet or something like it. Leverage the flexbox behavior and you are good to go:

  1. Use layout="column" and layout-fill attributes on your main wrapper (can be your body tag).
  2. Create your sections: header, main and footer.
  3. Use flex attribute on your main.

Check my example, based on @kuhnroyal pen.

Code | Full Page

Ravan Scafi
  • 6,382
  • 2
  • 24
  • 32
  • 2
    Bummer, this no longer works with Angular Material version 1.0.0-rc4. – Joe Martella Nov 23 '15 at 00:33
  • 1
    Works with 1.0.3 - though I didn't need "layout-fill" on the 'main wrapper' – David Poxon Mar 06 '16 at 03:46
  • It stopped working on angular-material@`1.1.1`. [works v0.8.3](http://codepen.io/aaroncalderon/pen/mOGaMy) | [broken v1.1.1](http://codepen.io/aaroncalderon/pen/wgJRxw/) – Aaron C Jan 23 '17 at 15:29
  • I found this http://stackoverflow.com/questions/34720648/angular-material-fixed-toolbar-and-sticky-footer and incorporated it on this codepen... [Working v1.1.1](http://codepen.io/aaroncalderon/pen/OWgNZV/) – Aaron C Jan 23 '17 at 16:40
21

You can get this to work with a small workaround.

  • use min-height: calc(100vh - 176px) on your main element, (176px = 2*88px for the md-toolbars)
  • remove the layout='column' from the root div
  • remove the layout-fill layout='column' from the body

I replaced the material css/js with CDN version 0.8.3 since my IE10 would crash with that amount of CSS/JS in a Codepen.

I tested this on Chrome, Firefox and IE10 - seems to work.

http://codepen.io/anon/pen/azgdOZ

kuhnroyal
  • 7,188
  • 1
  • 34
  • 47
7

So I am just experiementing with angular-material but what I did for this was

<div layout="column" layout-fill>
   <md-toolbar class="md-default-theme">
   <!-- your stuff -->
   </md-toolbar>
   <md-content layout-fill role="main">
      <!-- your main areas -->
   </md-content>
   <md-bottom-sheet>
      <div>I am a sticky footer</div>
   </md-bottom-sheet>
</div>

I have not experimented enough to know for sure whether this does everything they way I want, but is so far looks promising. Note if you content is not constrained, it would likely continually push the bottom-sheet down. if you used a overflow-y: auto on the md-content it might work (I don't have enough of my app built yet to test)

jadrake
  • 341
  • 3
  • 8
  • 1
    Is the intention of md-bottom-sheet though to provide contextual actions based on the state of the application? – Sam Storie Jan 02 '15 at 18:55
5

I didn't find any of the answers work reliably across browsers without one flaw or the other.

As pointed out in this SO answer, this works:

<md-toolbar></md-toolbar>
<md-content flex layout="column">
    <div layout="column" flex>
        <main flex="none"></main>
        <div flex></div>
        <footer flex="none"></footer>
    </div>
<md-content>

Here's a codepen for the example.

Community
  • 1
  • 1
creimers
  • 4,975
  • 4
  • 33
  • 55
  • Wish I could upvote more! Like you said, a lot of other solutions have subtle issues in one browser or another. The issue I was hitting in IE was so frustrating: https://codepen.io/ariscol/pen/rwwXWO – ctb Jun 22 '17 at 21:48