2

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

Ahmed Wagdi
  • 3,913
  • 10
  • 50
  • 116

2 Answers2

7

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']
})
Ranika Nisal
  • 910
  • 6
  • 20
0

Ranika Nisal's answer won't work well if the background has some opacity; there's another white background right behind the ion-menu. To implement an opacity on the entire side menu, I had to use the following code:

ion-split-pane{ 
    --border: none !important;
    ion-menu{
     --background: rgba(0,0,0,.3) !important; 
        ion-content{            
            --background: transparent !important; 
            ion-list-header{ 
                --background: transparent !important;
                --color: #FFFFFF !important;   
            }
            ion-list {
                background: transparent !important;
            }
            ion-item{
                --background: transparent !important;
                 --color: #FFFFFF !important;
                 ion-icon{ padding-right: 10px !important; }
            }
        }
    }
}
Cedric Ipkiss
  • 5,662
  • 2
  • 43
  • 72