Create a Responsive Toolbar using Angular Material

前端 未结 4 735
日久生厌
日久生厌 2020-12-13 15:14

I have created a toolbar using Angular Material. However, it is not responsive. How can I make the toolbar responsive?

Code for toolbar:



        
4条回答
  •  不知归路
    2020-12-13 16:02

    Here is my favorite way of creating a responsive Navigation Bar in Angular. If you use Angular 6, make sure you use a version 6.1+
    Working example on Stackblitz: https://stackblitz.com/edit/angular-v6xwte

    Example on a smaller screen:

    Example on a larger screen:

    Here are precise steps how to do it:

    1) Install necessary packages. Type in your terminal:

    npm install --save @angular/material @angular/cdk @angular/animations
    
    npm install @angular/flex-layout --save
    

    2) Import necessary modules in your app.module.ts

    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    import { FlexLayoutModule } from '@angular/flex-layout';
    import {
      MatIconModule, MatButtonModule, MatSidenavModule, MatToolbarModule
    } from '@angular/material';
    

    Remember to add these modules to the imports array below.

    3) Add Material Icons link to your index.html
    The link must go before any Angular content.

    
    

    4) In your styles.css add an Angular theme and set margins to 0%

    @import "~@angular/material/prebuilt-themes/indigo-pink.css";
    body{
        margin: 0%;
    }
    

    5) Add toolbar HTML code in your app.component.html

    
    

    6) Style the toolbar in your app.component.css

    .companyName{
        font-size: 150%;
    }
    
    .mat-toolbar{
      height: 7vh;
    }
    
    div {
        overflow: inherit;
    }
    
    .mat-sidenav-container{
      background-color: lightskyblue;
      min-height: 93vh !important;
    }
    
    a{
        text-decoration: none;
        font-size: 110%;
        white-space: normal;
    }
    
    button{
        font-size: 110%;
        min-width: min-content;
    }
    
    .example-icon {
        padding: 0 14px;
      }
    
      .example-spacer {
        flex: 1 1 auto;
      }
    
      .mat-sidenav-content{
          font-size: 200%;
          text-align: center;
      }
    

提交回复
热议问题