Using relative URL in CSS file, what location is it relative to?
According to W3:
Partial URLs are interpreted relative to the source of the style sheet, not relative to the document
Therefore, in answer to your question, it will be relative to /stylesheets/
.
If you think about this, this makes sense, since the CSS file could be added to pages in different directories, so standardising it to the CSS file means that the URLs will work wherever the stylesheets are linked.
CSS relative url to images
With the directory tree you are providing you don't have to change your path.
..
means the parent directory of the CSS file so the assets/
directory is implied.
background-image relative url doesnt work in CSS stylesheet
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");
}
Solution to relative path to image in CSS file depending on what file that includes it
The only way is with absolute paths. This means that in your CSS you must define an absolute path for your images, for example:
background-image: url(/images/image.png);
What's the problem? You need to know the absolute path where your folders are. For example, if you have this URL: http://localhost/myFolder/images/image.png
, your CSS will be:
background-image: url(/myFolder/images/image.png);
But when you upload it to a production server like this: http://myserver.com/images/image.png
, your CSS must to change to something like this:
background-image: url(/images/image.png);
So the best way is to develop in the same environment that your production server. This will be with the URL http://localhost/images/image.png
(develop) and http://myserver.com/images/image.png
(production).
Another way is to making friendly URLs, that avoids to you to make custom folders, and you can have all in one folder and the URLs will be rewrited by the server.
Good luck.
Related Topics
How to Create a Text Watermark Without an Image
Set Background-Image to a Blob: Uri
Why Bootstrap 3 Navbar Dropdown Doesn't Work in IE8
How to Disable the "Responsive" Grid in Bootstrap
Can You Use Rgba Colours in Gradients Produced with Internet Explorer's Filter Property
Two Images Background Inline Separate by Diagonal Border
How to Center Text Inside a Li Element Inside an Unordered List
How to Code an Arrow Using CSS
Laravel 5.3 - Issue Displaying Images from Public Folder Using @Extends & @Sections
Why Is "-Fx-Background-Radius: 10;" Not Working
Can't Use the Same Animation in Reverse for Class Toggle
How to Hide Only the First Element of a Type
CSS Is Not Loaded at All in Internet Explorer (Sec7113)
CSS - Force Overflowing Elements to Disappear If Partially Hidden
Right Aligned Bootstrap Container Which Also Aligns with Default Container
How to Set a Rotation Point for an Element in CSS