How to change the background color of ion-header in ionic 2?
30,767
Solution 1
You can change it globally if you want to in your variables.scss
under/in the theme folder:
$toolbar-background: blue;
For all the reference Ionic SASS Variables to override follow this link
Solution 2
<ion-header>
<ion-navbar color="color3">
<ion-title></ion-title>
</ion-navbar>
</ion-header>
you can set your custom color in src/theme/variable.scss like this :
$colors: (
primary: #8B4789,
secondary: #32db64,
danger: #f53d3d,
light: #f4f4f4,
dark: #222,
color1: #15c178,
color2: #8B4789,
color3 : #07904d,
color4: #673665,
brown: #B75E33,
ycBlue: #638AF1
);
I hope this will work for you
Solution 3
Check the official docs.
There is a color
attribute which takes key from the $colors
map.
<ion-header>
<ion-navbar color="danger">
<ion-title>TITLE</ion-title>
</ion-navbar>
</ion-header>
Solution 4
Set the color like this:
<ion-header>
<ion-navbar color="danger">
<ion-title>TITLE</ion-title>
</ion-navbar>
</ion-header>
Comments
-
Pawan over 3 years
How to change the header color? I tried below but didn't succeeded
<ion-header> <ion-navbar danger> <ion-title>TITLE</ion-title> </ion-navbar> </ion-header>
My variable.scss is:
$colors: ( primary: #387ef5, secondary: #32db64, danger: #f53d3d, light: #f4f4f4, dark: #222 );
-
Pawan about 7 yearsya it helped me thanks
-
Suraj Rao about 7 yearsyou are right..
-
Pawan about 7 yearsThat really helpful! Thanks
-
Yasir about 7 years@Pawan when you have set it globally but then you want one page/component with different color, you can put this in its
.scss
file.toolbar-background { background-color: #5381A7 !important; }
-
Pawan about 7 yearsBut what is the need of this On setting it globally the color is changing.. can u please explain?
-
Yasir about 7 yearsI just added an info... the global works fine for all the pages/components, but only if one page you need a different color for the header, so you just overwirte it by adding what I wrote in the comment above ,if the need arises thats all... otherwise, changing it globally does the trick alright
-
Pawan about 7 yearsokey i got it Thnku
-
Oleg almost 7 yearsYou also can see all possible Ionic variables in : ionicframework.com/docs/theming/overriding-ionic-variables
-
Prasanth Jaya over 6 yearsThe same applicable to ion-toolbar
-
Dmytro Grynets over 6 yearsIs it just me who sees a small fouc when opening menu with such styling?
-
Khurshid Ansari about 6 yearsGreat,this is help me