Angular material sidenav and fixed toolbar

10,505

Solution 1

You have to use md-sidenav inside the md-content container. Plus try to use md-content instead of div tag. In your example you gave wrong values to layout-align attribute. Please check the appropriate values in the Docs.

Here is the basic structure for your requirement.

<md-content flex>
    <md-toolbar>
    </md-toolbar>

    <md-content layout="column" layout-fill>
        <!-- content -->

        <md-sidenav>
        </md-sidenav>
    </md-content>
</md-content>

here is the working pen. http://codepen.io/next1/pen/xOqMjy

Solution 2

You need to add layouts for all containers and move the toolbar out of the md-content that should be scrolled.

<div layout="row" flex>
 <md-sidenav></md-sidenav>
 <div layout="column" flex>
   <md-toolbar></md-toolbar>
   <md-content></md-content>
 </div>
 <md-sidenav></md-sidenav>
</div>

Here's a working demo: http://codepen.io/anon/pen/EyWJKK?editors=1010

Share:
10,505

Related videos on Youtube

A.W.
Author by

A.W.

Software developer. Electronics hobbyist.

Updated on June 04, 2022

Comments

  • A.W.
    A.W. almost 2 years

    I copied this sidenav demo from the angular material docs. https://material.angularjs.org/latest/demo/sidenav

    And added the first toolbar demo to it from https://material.angularjs.org/latest/demo/toolbar

    What I want is the toolbar to be fixed.

    Codepen demo: http://codepen.io/gvorster/pen/BzWvGe

    When adding this style the toolbar is fixed.

    <md-toolbar class="md-hue-2" style="position:fixed !important">
    

    But the icons on the right are gone.

    enter image description here

    Resizing the screen until the sidenav is hidden will show the right side icons.

    enter image description here

    Removing the style shows the right side icons but the toolbar is not fixed:

    enter image description here

    Is there a way to get a sticky toolbar and have the rigth side icons shown.

  • Aarmora
    Aarmora over 7 years
    Is there a way to do this with material for angular 2? It doesn't appear that md-content exists and I'm having the exact same issue as @Guus.