Problem with local image


#1

Hi,
I’m new with Ionic 2. I’m trying to set background to the view.
I have an image in www/img and in scss I set the background with this code:

.login {
      background:  linear-gradient(
      rgba(0, 0, 0, 0.75), 
      rgba(0, 0, 0, 0.1)
    ), url(/img/sfondologin.jpg);
      background-repeat: no-repeat;
      background-size: cover;
      background-position: center;
      width: 100%;
      height: auto;      
      z-index: 2;
      position: relative;
  }

With command ionic serve I see the image in the browser. The problem is when I run the app in android device or ios simulator.
I have this error:
Failed to load resource: net::ERR_FILE_NOT_FOUND (file:///img/sfondologin.jpg)
Can you help me?

Thanks,
Stefano


#2

if you start your path with / it starts at the root folder of your device/storage

Try:

background: linear-gradient(
  rgba(0, 0, 0, 0.75), 
  rgba(0, 0, 0, 0.1)
), url("img/sfondologin.jpg");

#3

It doesn’t work.
Without ‘/’ I have this error:
Failed to load resource: net::ERR_FILE_NOT_FOUND (file:///android_asset/www/build/css/img/sfondologin.jpg)


#4

okay take a look where your image folder is --> so try ‘…/’


#5

Ok, now it works :slight_smile:
So the correct place for the images is www/build/img?