Constantine Awa-ao
Constantine Awa-ao

Reputation: 35

ionic 4 ion-content background-image not showing on device

I'm trying to add a background image in my ion-content here is my current code:

ion-content{
    --background: none;
    background-image: url('/assets/images/home-background.png');
    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover;
    text-align: center;
}

I also tried the following but same thing happened.

ion-content{
    --background: url('/assets/images/home-background.png')  no-repeat center center / cover;
    text-align: center;
}

It is working in browser but when I'm doing ionic cordova run android, the background image is not showing. I also tried to change the url to url('../assets/images/home-background.png'), url('./assets/images/home-background.png') and url('../images/home-background.png') but it's giving me error.

I tried to check it and debug it and maybe this can help, I clicked the url and it brings me to the resources which shows me the image

In this second image, I saw the home-background.png

Upvotes: 1

Views: 2520

Answers (5)

karma dorji
karma dorji

Reputation: 11

You can try to change your image url as shown below

ion-content{
--background: none;
background-image: url('../../assets/images/home-background.png');
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
text-align: center;
}

this worked for me.

Upvotes: 0

Constantine Awa-ao
Constantine Awa-ao

Reputation: 35

didn't have the chance to solve this problem using the ionic-content, so what I did is to change the ionic-content to div, and it solve my problem. Working in web and android device.

Upvotes: 2

naveen pandi
naveen pandi

Reputation: 645

background-image: url('..assets/img/home-background.png');

if u have set path just type ../ or ./ automatically path will suggestion

Upvotes: 0

Rohit Upadhyay
Rohit Upadhyay

Reputation: 186

Try changing the path keep images in main www/assets/img folder and then set

background-image: url('assets/img/home-background.png');

Upvotes: 0

Khurshid Ansari
Khurshid Ansari

Reputation: 5075

Open scss file:

ion-content {
    background: url('../../assets/img/myBg.jpg') center bottom no-repeat;
    background-size: 100%; 
}

Upvotes: 0

Related Questions