user2652527
user2652527

Reputation: 21

CSS Background-Image URL

When writing CSS Style for body I encountered a problem and was wondering if anyone can explain the difference.

when I used this

 body {
 background-image: url('img/bg.png');
 }

it did not work. http://www.w3schools.com/cssref/pr_background-image.asp

but when I used this

 body {
 background-image: url('../img/bg.png');
 }

It works fine. I'm quessing it might be because it is in a folder I have to use the '../' but I just wanted to ask to be sure.

Upvotes: 2

Views: 5406

Answers (1)

Oleksandr Savchenko
Oleksandr Savchenko

Reputation: 692

Ordinary project structure look like this:

index.html
css/
    style.css
img/
    bg.png

When you use

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

that means that location of the image is css/img/bg.png, and when you use

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

that means that that location of the image is img/bg.png (../ - one level higher from current folder, ../../ two levels higher, etc)

Upvotes: 2

Related Questions