I want to set an image as background of an ion-header/ion-toolbar.
For Ionic version 3 this solution worked very well: How to set background image for header?
It just used the class “toolbar-background” for this purpose. This class also exists in Ionic 4.
But in ionic 4 it seems, that the css of the pages is only applied to the elements in ion-content, so it won’t change anything regarding the header. Even if I declare the necessary styles in the global.scss it is not applied to the header.
Edit: I need a solution to change the header per page. Pasting the css into the global.scss was just to verify that it works nowhere.
I found a somewhat hacky solution that works. The problem why whe can’t use css to style the header anymore is that ionic 4 encapsulates it inside a web component. Web components are meant to be uneffected by outside css.
Luckily we can absuse the color variables in “theme/variables.scss” to insert an image into the header. Because it’s content is direcly used as value for the css background property it is possible to do something like this:
--ion-color-medium: url("assets/custom-image.jpg") center / 100%;