Problem with local image

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

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");
1 Like

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)

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

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