My ion-content is overlapping with the header in Ionic 4
To avoid the overlapping of ion-content
you should add a style to the ion-content
<ion-content class="content"></ion-content>
.content{
margin-top: 50px;
}
You can try the above way or else try if this works..
<ion-content padding>
</ion-content>
Add padding to the ion-content
tag
You can check any other solution suits for you here ion-content overlaps with header
For those who don't want to deal with approximative css styles, @AJT82 pointed out the right way to deal with this. By creating a custom header component, you won't have to use any margin or padding styles. Also, you will have the choice to display a custom title on specific page.
Assuming my toolbar needs to be on my component HomePageModule
, I created a subcomponent toolbar.ts
. Then I import it inside home.module.ts
and declare it into home.page.html
.
toolbar.ts
using Input
to retrieve the title
parameter from html:
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-toolbar',
templateUrl: 'toolbar.html',
styleUrls: ['toolbar.scss']
})
export class AppToolbar {
@Input() public title: string;
constructor() {}
}
toolbar.html
display the title
receive from the module:
<ion-header>
<ion-toolbar>
<ion-title>{{title}}</ion-title>
</ion-toolbar>
</ion-header>
home.module.ts
import the toolbar
's module:
import { AppToolbar } from './toolbar/toolbar';
@NgModule({
declarations: [AppToolbar]
})
export class HomePageModule {}
home.page.html
then, declare it inside the home
template with the title
parameter:
<app-toolbar [title]="'My Custom Title'"></app-toolbar>
<ion-content>
<!-- content -->
</ion-content>
Each page should import this component and declare it into its html page. By using this, the toolbar
doesn't overloap the content page, and it can display a specific title.