Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set background color IONIC 4

I having problems trying to change the background color in just one IONIC 4 (--type=angular) page. I am trying to add a class for the ion-content. In my html file I Have:

<ion-content class="fondologin"> ... </ion-content> 

In my sass I have:

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

The background color is never changed. If I add --ion-background-color:#111D12; in variables.scss the background is successfully changed for every page but I just one to change the color in one page. How can I achieve this?

like image 682
Kevin Sanchez Avatar asked Nov 29 '18 04:11

Kevin Sanchez


People also ask

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 change the theme in ion 4?

The fastest way to change the theme of your Ionic app is to set a new value for primary , since Ionic uses the primary color by default to style most components. Colors can be removed from the map if they aren't being used, but primary should not be removed.


2 Answers

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.

like image 104
Kevin Sanchez Avatar answered Sep 23 '22 08:09

Kevin Sanchez


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; } 
like image 27
Edward Choh Avatar answered Sep 24 '22 08:09

Edward Choh