Set an image as background in ion-slide

Quico Llinares Llorens picture Quico Llinares Llorens · May 11, 2017 · Viewed 7.3k times · Source

I am trying to do an intro for an app with < ion-slides page>, my problem comes to set an image as background, I am trying to do this on my HTML:

<ion-header>

  <ion-navbar>
    <ion-title>Intro</ion-title>
  </ion-navbar>

</ion-header>


<ion-content padding>

</ion-content>

<ion-slides pager>

  <ion-slide style="background-image: url(/../../www/img/fondo.png)">
    <h2>Slide 1</h2>
  </ion-slide>

  <ion-slide style="background-color: mediumpurple">
    <h2>Slide 2</h2>
  </ion-slide>

  <ion-slide style="background-color: mediumpurple">
    <h2>Slide 3</h2>
  </ion-slide>

</ion-slides>

As it can be seen, the first slide should show the image, but what I get is this: enter image description here

Thanks for helping!

Answer

Suraj Rao picture Suraj Rao · May 11, 2017

Your background image path is incorrect.

The image should be saved in /src/assets/img/fondo.png. This is copied to /www/assets/img/fondo.png during the build process.

Your html code will have :

 <ion-slide style="background-image: url(../assets/img/fondo.png)">