1

I'm having some problems because I can't set my background photo from CSS file.

I'm using netbeans. I have a folder called css and inside I have the global.css. Inside global.css i have this code:

body{
    background-image: url(/images/background.jpg);
}

Background.jpg is inside a folder called images, the structure is the following:

--Web Pages
     -css
         global.css
     -images
         background.jpg

     -index.html
--Source Packages
--etc

It is not working, why?

user2911701
  • 69
  • 1
  • 10

3 Answers3

2

Is the css loading correctly? If so, then take a look to the url: using trailing hash before images/ links to the root of your server, but your image it's not there. Use ../ to go upper in your filesistem and then enter into your images folder. This should work:

body{
    background-image: url(../images/background.jpg);
}
Alan Berdinelli
  • 300
  • 3
  • 8
2

Change the path to this: background-image: url(../images/background.jpg);

Jonathan Zúñiga
  • 645
  • 3
  • 13
  • 25
1

Currently, it is inside the css(global.css) it should go one level up (css folder, images folder) and then go inside the images folder.

body{
    background-image: url(../images/background.jpg);
}
Alex
  • 8,461
  • 6
  • 37
  • 49
  • Thanks, it solved the problem. – user2911701 Nov 05 '15 at 18:07
  • @user2911701 You are welcome. [This is useful article for css paths](https://css-tricks.com/quick-reminder-about-file-paths/) and [this one](http://jeffreybarke.net/2013/06/paths-and-urls-relative-and-absolute/) – Alex Nov 05 '15 at 18:17