Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 Material 2 top navbar\toolbar

I have the toolbar working but it leaves a gap around instead of smooth at the top of the page.

Also I would like it to be sticky but have not yet worked on that part since it doesn't look like my toolbar implementation is a "header". What am I doing wrong or am I using the wrong component?

Toolbar with gaps

<md-toolbar color="primary">
    <i class="material-icons app-toolbar-menu">menu</i>
    <span class="app-toolbar-filler"></span>
    <md-sidenav>
    </md-sidenav>
</md-toolbar>
like image 227
user1552172 Avatar asked May 07 '17 06:05

user1552172


2 Answers

The accepted other answer seems kind of hacky, since your toolbar isn't really a sidenav. Here's a better way to do it.

In styles.css, set:

body {
    margin: 0;
}

However, this also gets rid of the margins for the rest of the HTML. If you do not want this, wrap the rest of the HTML in a <div> and add a margin to that.

like image 124
Oliver Ni Avatar answered Sep 18 '22 06:09

Oliver Ni


Simply place your code inside a md-sidenav-container element and add an attribute fullscreen:

<md-sidenav-container fullscreen>
    <md-toolbar color="primary">
        <i class="material-icons app-toolbar-menu">menu</i>
        <span class="app-toolbar-filler"></span>
        <md-sidenav>
        </md-sidenav>
    </md-toolbar>
</md-sidenav-container>

Plunker Demo

UPDATE: You should use the answer above mine. It doesn't require a sidenav.

like image 24
Edric Avatar answered Sep 19 '22 06:09

Edric