How to set background color IONIC 4

元气小坏坏 提交于 2019-11-30 04:50:14
Kevin Sanchez

For some reason I solved it this way:

First of all I added --ion-background-color:#ffffff; in the variables.scss file inside theme folder.

In my Page scss I wrote:

ion-content{

    --ion-background-color:#111D12;
}

After that the background was successful set.

I am going to repost the top commented answer , with an extra explanation

ion-content{
    --ion-background-color:#111D12;
}

Starting from ionic 4, Ionic component implements the concept of shadowDOM, and the old method of finding css selectors in the component that implements shadowDOM no longer works

As such, any modification can only be made if you change the variable that the component references

for example, if ion content references

--ion-background-color: #ffffff

The only way you can modify the background color is by doing this in your css file

ion-content{
    --ion-background-color:#111D12;
}

You can use like this...working good on my page.

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

I hope it helps you :)

Also works in android deploy, If you need transparency in your background. You must setup like this way, i tried another way but doesn't work, only this way works for me.

ion-content {
  --background: rgba(0, 255, 0, 0.5);
}

It might be you CSS selector that is not enough acurate.

Try this :

ion-content.fondologin{
    background-color: #111D12!important;
}

If it is still not working, then inspect your ion-content element and try to find your CSS, and which property or other selector is overriding it

Rahul Jograna

Try this one:

    :host {
      ion-content {
        ion-background-color: #d5ffd5;
      }
    }

//Or 

 page-name{
      ion-content {
        ion-background-color: #d5ffd5;
      }
    }

For changing the background on only one page:

ion-content{
--ion-background-color:  #00ABE1 !important;
}

Do not forget the !important or it might not work.

Nayan Dubey

Try this.

ion-content{
background-color:  #000000(use your color here) !important;
}

and let me know it is working for you or not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!