user3241620
user3241620

Reputation: 95

background-image relative url doesnt work in CSS stylesheet

I am keeping my both html and css stylesheet files in the same folder and images in a img folder.

Relative links to images works on html:

<img src="img\Philippines.png">

but it doesn't work in css when i write:

#Philippines {
background-image:url("../img/UK.png");

it does work when i put full url:

#Philippines {
background-image:url("file:///C:/Users/User/Dropbox/+HOROS%20code/img/Philippines.png");

I want it to work with relative urls, any help?

Upvotes: 1

Views: 16793

Answers (1)

MightyPork
MightyPork

Reputation: 18861

url() in CSS is relative to the location of your CSS file.

If I understand you correctly, this is your folder structure:

-+-img
 |  +--images
 +html_file
 +css_file

If so, try this:

#Philippines {
    background-image:url("img/UK.png");
}

Upvotes: 6

Related Questions