Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set header background color in ionic 4

Tags:

I am trying in different way which I followed link(How to set background color IONIC 4) for header background color and tried as per ionic 2 and ionic 3 as well:

I am able to make background color for ion-content, but background color is not coming for header.

Code:

<ion-header>      <ion-toolbar style="background-color: red">          <ion-title>Login</ion-title>      </ion-toolbar>  </ion-header>

Please need your support.

like image 766
Arindam Avatar asked Nov 30 '18 09:11

Arindam


People also ask

How do I change the background on my header?

Change the color or image of the header Go to the Design tab. Click Customize to expand the set of choices for customizing your theme. Click Header Image to choose an image to be the background of the header. Click Header background to choose a color for the header section.

How do I change the background color in Ionic toolbar?

Styling the Ionic 5 Toolbar ( ion-toolbar ) $toolbar-background: #123456; $toolbar-border-color: #123456; $toolbar-text-color: #123456; $toolbar-active-color: #123456; $toolbar-inactive-color: #123456; Just put them in the variables. scss file and change their values to your desired colors.

How do you style an ion header?

To fix this you need to add a 'has-header' or a 'has-subheader' class to the ion-content tags of your screens. Open one of your HTML files from www/templates and add the has-subheader class to the ion-content. If you only use header in your app, you will need to add the has-header class instead.


2 Answers

It seems like the ion-header acts more as a container for an inner ionic component (like an ion-toolbar). I looked over the Ionic v4 ion-toolbar documentation. This component has many custom css custom properties, including --background, that can be customized. This may be what you're looking for.

Assuming you used the CLI to create a 'login' page component, you can add a new css class definition to the login.scss file:

.new-background-color{     --background: #54d61c; } 

And then refer to it in your login.page.html file:

<ion-header>   <ion-toolbar class="new-background-color">         <ion-title>Login</ion-title>   </ion-toolbar> </ion-header> 
like image 54
Rich Tillis Avatar answered Sep 19 '22 07:09

Rich Tillis


I've used the following code snippet to change color of header:

<ion-header>     <ion-toolbar color="primary">         <ion-title>Login</ion-title>     </ion-toolbar> </ion-header> 

Instead of primary color, you can use any custom color from variables.scss file.

like image 40
farhad rubel Avatar answered Sep 17 '22 07:09

farhad rubel