Search code examples
angularionic-frameworkionic4

Change side menu background color ionic 4


Trying to change the side sliding menu background's color in my ionic 4 project

here is my code :

<ion-app>
  <ion-split-pane>
    <ion-menu>
      <ion-header>
        <ion-toolbar color="medium">
          <ion-title>Menu</ion-title>
        </ion-toolbar>
      </ion-header>
      <ion-content background = "medium">
        <ion-list>
          <ion-menu-toggle auto-hide="false" *ngFor="let p of appPages">
            <ion-item [routerDirection]="'root'" [routerLink]="[p.url]">
              <ion-icon slot="start" [name]="p.icon"></ion-icon>
              <ion-label>
                {{p.title}}
              </ion-label>
            </ion-item>
          </ion-menu-toggle>
        </ion-list>
      </ion-content>
    </ion-menu>
    <ion-router-outlet main></ion-router-outlet>
  </ion-split-pane>
</ion-app>

And it only changes the ion-toolbar background color, here is how it looks

enter image description here


Solution

  • To do this in ionic 4 you have to add to your pages css (or scss) file

    ion-menu{
          ion-content{
              --ion-background-color:#color
          }
    }
    

    Since the menu is most probably on the app.component.html you may not have a css file generated for it in which case you can easily link one by specifying it at the app.component.ts using

    @Component({
         selector: 'app-root',
         templateUrl //,
         stykeUrls :['yourstyles.scss']
    })