How do I set an image in the background of the page?

2

I'm trying to run my project with a background image as follows:

The image is in the path:
webapp / resources / libimagens / bg.png

The CSS file is in the path:
webapp / resources / libcss / style.css

Within the body{} tag in CSS I've done it the way below, but it did not work.

background-image: url(../libimagens/bg.png)

Thank you to anyone who has a solution.

    
asked by anonymous 02.10.2015 / 06:01

2 answers

2

If the CSS file is in the path:
webapp/resources/styles.css

And the image is in the path:
webapp/resources/libimagens/bg.png

The correct path to the background-image property will be:

background-image: url(libimagens/bg.png);

When you use - background-image: url(../libimagens/bg.png) , you are returning a folder back.

The paths:

  • Starting with " / " returns to the root directory and starts from there
  • Beginning with " ../ " returns a directory backwards and starts from there
  • Starting with " ../../ " returns two directories back and starts from there
  • (and so forth ...)
  • To advance / move forward, just start with the first subdirectory and move forward
    (% with%)

more info

    
02.10.2015 / 07:08
2

Using ../ , should be working, try to use quotation marks this way:

background-image: url("../libimagens/bg.png") , I believe it will solve.

But another very simple solution is to use the absolute path to the image, for example:

background-image: url(http://www.urldoseusite.com/libimagens/bg.png)

    
02.10.2015 / 20:05