background-image relative url doesnt work in CSS s

2019-06-13 16:38发布

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?

1条回答
唯我独甜
2楼-- · 2019-06-13 16:57

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");
}
查看更多
登录 后发表回答