ionic 4: changing ion-content background does not work

≡放荡痞女 提交于 2019-12-03 03:13:09

You can use the CSS-Variable --background to change the background of ion-content.

Example:

ion-content{
    --background: #fff url('../../assets/images/cover.jpg') no-repeat center center / cover;
}

Put this into your components, pages or global scss.

For reference see: https://beta.ionicframework.com/docs/api/content#css-custom-properties

I solved the problem doing the following:

ion-content {
    --background: none;
    background-image: url('/assets/imgs/page_bg.jpg');
    background-position: center top;
    background-repeat: no-repeat;
    background-size: cover;
}

This will disabled background and then set the correct one.

I have encountered the similar situation, having ionic background css property leads to flickering issues on IOS

try the following if you have encountered flickering issue

:host {
  ion-content {
    --background:none;
    background:url(''../../assets/images/cover.jpg');
    background-size: cover;
    background-position: center center;
  }
}

for anyone having keyboard issues (background resizes on keyboard show) install Keyboard plugin

https://ionicframework.com/docs/native/keyboard/

and add the following code on your config.json

<preference name="keyboardResize" value="false" />
<preference name="keyboardResizeMode" value="native" />

Note: this may hide item beneath the keyboard when its shown (I have tested only on iOS)

Jaikant Chaturvedi

I tried answer from @rchau, but it did not work in my case. Instead, I put this code in my project and it has done the right thing:

ion-content{
    --background:url('../../assets/images/cover.jpg') 0 0/100% 100% no-repeat;
}

04-05-2019

This is the working solution for me.

ion-content {
    --background: url('/assets/img/background/background.png') no-repeat 100% 100%;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!