Sam Storie Sam Storie - 1 year ago 812
AngularJS Question

How to implement the classic "sticky footer" with angular-material?

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

are used in containers with fixed heights, then they work great. I'm struggling with how to throw them inside a
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.


<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>
<main class='md-padding' layout="row" flex>
<div flex>
<md-card ng-if="displayContent" ng-repeat = "card in cards">
<div flex>
<md-card ng-if="displayContent" ng-repeat = "card in cards">
<md-toolbar class="md-medium-tall">
<div layout="row" layout-align="center center" flex>


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

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

$scope.displayContent = true;

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


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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download